This short tutorial covers the very basic use cases to get you started with diseq. More usage details can be found in the documentation of the package.
Load the required libraries.
Prepare the data. Normally this step is long and it depends on the nature of the data and the considered market. For this example, we will use simulated data. Although we could simulate data independently from the package, we will use the top-level simulation functionality of diseq to simplify the process. See the documentation of simulate_model_data
for more information on the simulation functionality. Here, we simulate data using a data generating process for a market in disequilibrium with stochastic price dynamics.
nobs <- 2000
tobs <- 5
alpha_d <- -0.1
beta_d0 <- 9.8
beta_d <- c(0.3, -0.2)
eta_d <- c(0.6, -0.1)
alpha_s <- 0.1
beta_s0 <- 5.1
beta_s <- c(0.9)
eta_s <- c(-0.5, 0.2)
gamma <- 1.2
beta_p0 <- 3.1
beta_p <- c(0.8)
sigma_d <- 1
sigma_s <- 1
sigma_p <- 1
rho_ds <- 0.0
rho_dp <- 0.0
rho_sp <- 0.0
seed <- 443
stochastic_adjustment_data <- simulate_model_data(
"diseq_stochastic_adjustment", nobs, tobs,
alpha_d, beta_d0, beta_d, eta_d,
alpha_s, beta_s0, beta_s, eta_s,
gamma, beta_p0, beta_p,
sigma_d = sigma_d, sigma_s = sigma_s, sigma_p = sigma_p,
rho_ds = rho_ds, rho_dp = rho_dp, rho_sp = rho_sp,
seed = seed
)
The constructor sets the basic parameters for model initialization and constructs a model object. The needed arguments for a construction call are configured as follows:
diseq_directional
, diseq_deterministic_adjustment
, and diseq_stochastic_adjustment
models require calculating the first differences.lm
formula. Indicator variables and interaction terms will be created automatically by the constructor. For the diseq_directional
model, the price cannot go in both equations. For the rest of the models, the price can go in both equations if treated as exogenous. The diseq_stochastic_adjustment
requires also the specification of price dynamics.demand_specification <- paste0(price_column, " + Xd1 + Xd2 + X1 + X2")
supply_specification <- "Xs1 + X1 + X2"
price_specification <- "Xp1"
Using the above parameterization, construct the model objects. Here, we construct an equilibrium model and four disequilibrium models, using in all cases the same data simulated by the process based on the stochastic price adjustment model. Of course, this is only done to simplify the exposition of the functionality. The constructors of the models that use price dynamics information in the estimation, i.e. diseq_directional
, diseq_deterministic_adjustment
, and diseq_stochastic_adjustment
, will automatically generate lagged prices and drop one observation per entity.
eqmdl <- new(
"equilibrium_model",
key_columns,
quantity_column, price_column,
demand_specification, paste0(price_column, " + ", supply_specification),
stochastic_adjustment_data,
use_correlated_shocks = use_correlated_shocks, verbose = verbose
)
#> Info: This is 'Equilibrium FIML with correlated shocks' model
bsmdl <- new(
"diseq_basic",
key_columns,
quantity_column, price_column,
demand_specification, paste0(price_column, " + ", supply_specification),
stochastic_adjustment_data,
use_correlated_shocks = use_correlated_shocks, verbose = verbose
)
#> Info: This is 'Basic with correlated shocks' model
drmdl <- new(
"diseq_directional",
key_columns, time_column,
quantity_column, price_column,
demand_specification, supply_specification,
stochastic_adjustment_data,
use_correlated_shocks = use_correlated_shocks, verbose = verbose
)
#> Info: This is 'Directional with correlated shocks' model
#> Info: Dropping 2000 rows by generating 'LAGGED_P'.
#> Info: Sample separated with 9 rows in excess supply and 7991 in excess demand regime.
damdl <- new(
"diseq_deterministic_adjustment",
key_columns, time_column,
quantity_column, price_column,
demand_specification, paste0(price_column, " + ", supply_specification),
stochastic_adjustment_data,
use_correlated_shocks = use_correlated_shocks, verbose = verbose
)
#> Info: This is 'Deterministic Adjustment with correlated shocks' model
#> Info: Dropping 2000 rows by generating 'LAGGED_P'.
#> Info: Sample separated with 9 rows in excess supply and 7991 in excess demand regime.
samdl <- new(
"diseq_stochastic_adjustment",
key_columns, time_column,
quantity_column, price_column,
demand_specification, paste0(price_column, " + ", supply_specification),
price_specification,
stochastic_adjustment_data,
use_correlated_shocks = use_correlated_shocks, verbose = verbose
)
#> Info: This is 'Stochastic Adjustment with correlated shocks' model
#> Info: Dropping 2000 rows by generating 'LAGGED_P'.
First, we need to set the estimation parameters and choose and estimation method. The only model that can be estimated by least squares is the equilibrium_model
. To estimate the model with this methodology call diseq::estimate
with method = 2SLS
set. The equilibrium_model
can also be estimated using full information maximum likelihood, as it is the case for all the disequilibrium models. One may choose an optimization method and the corresponding optimization controls. The available methods are:
Nelder-Mead
: Does not require the gradient of the likelihood to be known.
BFGS
: Uses the analytically calculated gradients. By default the diseq package uses this method.
L-BFGS-B
: Constrained optimization.
optimization_method <- "BFGS"
optimization_controls <- list(REPORT = 10, maxit = 10000, reltol = 1e-6)
use_heteroscedasticity_consistent_errors <- TRUE
cluster_errors_by <- c("id")
Then, estimate the models. See the documentation for more options.
eqmdl_reg <- estimate(eqmdl, method = "2SLS")
eqmdl_est <- estimate(eqmdl,
control = optimization_controls, method = optimization_method,
cluster_errors_by = cluster_errors_by
)
bsmdl_est <- estimate(bsmdl,
control = optimization_controls, method = optimization_method,
use_heteroscedasticity_consistent_errors = use_heteroscedasticity_consistent_errors
)
drmdl_est <- estimate(drmdl,
control = optimization_controls, method = optimization_method,
use_heteroscedasticity_consistent_errors = use_heteroscedasticity_consistent_errors
)
damdl_est <- estimate(damdl,
control = optimization_controls, method = optimization_method,
cluster_errors_by = cluster_errors_by
)
samdl_est <- estimate(samdl,
control = optimization_controls, method = optimization_method,
cluster_errors_by = cluster_errors_by
)
Calculate marginal effects on the shortage probabilities. Diseq offers two marginal effect calls out of the box. The mean marginal effects and the marginal effects ate the mean. Marginal effects on the shortage probabilities are state-dependent. If the variable is only in the demand equation, the output name of the marginal effect is the variable name prefixed by D_
. If the variable is only in the supply equation, the name of the marginal effect is the variable name prefixed by S_
. If the variable is in both equations, then it is prefixed by B_
.
variables <- c(price_column, "Xd1", "Xd2", "X1", "X2", "Xs1")
bsmdl_mme <- sapply(variables,
function(v) get_mean_marginal_effect(bsmdl, bsmdl_est, v),
USE.NAMES = FALSE
)
drmdl_mme <- sapply(variables,
function(v) get_mean_marginal_effect(drmdl, drmdl_est, v),
USE.NAMES = FALSE
)
damdl_mme <- sapply(variables,
function(v) get_mean_marginal_effect(damdl, damdl_est, v),
USE.NAMES = FALSE
)
samdl_mme <- sapply(variables,
function(v) get_mean_marginal_effect(samdl, samdl_est, v),
USE.NAMES = FALSE
)
bsmdl_mem <- sapply(variables,
function(v) get_marginal_effect_at_mean(bsmdl, bsmdl_est, v),
USE.NAMES = FALSE
)
drmdl_mem <- sapply(variables,
function(v) get_marginal_effect_at_mean(drmdl, drmdl_est, v),
USE.NAMES = FALSE
)
damdl_mem <- sapply(variables,
function(v) get_marginal_effect_at_mean(damdl, damdl_est, v),
USE.NAMES = FALSE
)
samdl_mem <- sapply(variables,
function(v) get_marginal_effect_at_mean(samdl, samdl_est, v),
USE.NAMES = FALSE
)
cbind(
bsmdl_mme, drmdl_mme, damdl_mme, samdl_mme, bsmdl_mem, drmdl_mem, damdl_mem,
samdl_mem
)
#> bsmdl_mme drmdl_mme damdl_mme samdl_mme bsmdl_mem
#> B_P -0.03116252 -0.0001311817 -0.0009663191 -0.04037366 -0.04445984
#> D_Xd1 0.06380171 0.0003380489 0.0014376743 0.06073446 0.09102643
#> D_Xd2 -0.03847228 0.0001247948 -0.0009408077 -0.03545453 -0.05488873
#> B_X1 0.22980175 0.0009789019 0.0053218947 0.22223228 0.32786008
#> B_X2 -0.07253721 0.0020569042 -0.0012012494 -0.05206977 -0.10348944
#> S_Xs1 -0.19442845 -0.0006311324 -0.0044621154 -0.19309798 -0.27739271
#> drmdl_mem damdl_mem samdl_mem
#> B_P -6.251634e-05 -0.0002319415 -0.05602628
#> D_Xd1 1.611016e-04 0.0003450789 0.08428082
#> D_Xd2 5.947257e-05 -0.0002258181 -0.04920002
#> B_X1 4.665084e-04 0.0012773920 0.30839032
#> B_X2 9.802444e-04 -0.0002883308 -0.07225689
#> S_Xs1 -3.007744e-04 -0.0010710228 -0.26796084
Copy the disequilibrium model tibble
and augment it with post-estimation data. The disequilibrium models can be used to estimate:
Shortage probabilities. These are the probabilities that the disequilibrium models assign to observing a particular extent of excess demand.
Normalized shortages. The point estimates of the shortages are normalized by the variance of the difference of the shocks of demand and supply.
Relative shortages: The point estimates of the shortages are normalized by the estimated supplied quantity.
mdt <- tibble::add_column(
bsmdl@model_tibble,
normalized_shortages = c(get_normalized_shortages(bsmdl, bsmdl_est@coef)),
shortage_probabilities = c(get_shortage_probabilities(bsmdl, bsmdl_est@coef)),
relative_shortages = c(get_relative_shortages(bsmdl, bsmdl_est@coef))
)
How is the sample separated post-estimation? The indices of the observations for which the estimated demand is greater than the estimated supply are easily obtained.
abs_estsep <- c(
nobs = length(has_shortage(bsmdl, bsmdl_est@coef)),
nshortages = sum(has_shortage(bsmdl, bsmdl_est@coef)),
nsurpluses = sum(!has_shortage(bsmdl, bsmdl_est@coef))
)
print(abs_estsep)
#> nobs nshortages nsurpluses
#> 10000 6005 3995
rel_estsep <- abs_estsep / abs_estsep["nobs"]
names(rel_estsep) <- c("total", "shortages_share", "surpluses_share")
print(rel_estsep)
#> total shortages_share surpluses_share
#> 1.0000 0.6005 0.3995
if (requireNamespace("ggplot2", quietly = TRUE)) {
ggplot2::ggplot(mdt, ggplot2::aes(normalized_shortages)) +
ggplot2::geom_density() +
ggplot2::ggtitle(paste0(
"Normalized shortages density (",
get_model_description(bsmdl), ")"
))
}
All the model estimates support the summary
function. The eq_2sls
provides also the first stage estimation. The summary
output comes from systemfit
. The remaining models are estimated using maximum likelihood and the summary
functionality is based on bbmle
.
summary(eqmdl_reg$first_stage_model)
#>
#> Call:
#> lm(formula = first_stage_formula, data = object@model_tibble)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -16.6628 -5.8648 0.6677 6.2961 18.0452
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 20.63325 0.84994 24.276 < 2e-16 ***
#> Xd1 0.35530 0.15154 2.345 0.0191 *
#> Xd2 -0.06874 0.15005 -0.458 0.6469
#> X1 0.58717 0.15052 3.901 9.65e-05 ***
#> X2 -0.18630 0.15021 -1.240 0.2149
#> Xs1 -0.60577 0.15126 -4.005 6.25e-05 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 7.503 on 9994 degrees of freedom
#> Multiple R-squared: 0.003851, Adjusted R-squared: 0.003353
#> F-statistic: 7.728 on 5 and 9994 DF, p-value: 2.898e-07
summary(eqmdl_reg$system_model)
#>
#> systemfit results
#> method: 2SLS
#>
#> N DF SSR detRCov OLS-R2 McElroy-R2
#> system 20000 19989 597716 87.6228 -29.7213 -0.763774
#>
#> N DF SSR MSE RMSE R2 Adj R2
#> demand 10000 9994 488427 48.8721 6.99086 -49.2083 -49.2334
#> supply 10000 9995 109289 10.9344 3.30671 -10.2344 -10.2389
#>
#> The covariance matrix of the residuals
#> demand supply
#> demand 48.8721 -21.1367
#> supply -21.1367 10.9344
#>
#> The correlations of the residuals
#> demand supply
#> demand 1.000000 -0.914347
#> supply -0.914347 1.000000
#>
#>
#> 2SLS estimates for 'demand' (equation 1)
#> Model Formula: Q ~ P + Xd1 + Xd2 + X1 + X2
#> <environment: 0x562e83c11650>
#> Instruments: ~Xd1 + Xd2 + X1 + X2 + Xs1
#> <environment: 0x562e83c11650>
#>
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 25.151899 4.501475 5.58748 2.3643e-08 ***
#> P -0.898931 0.232656 -3.86378 0.00011235 ***
#> Xd1 0.467931 0.163652 2.85930 0.00425451 **
#> Xd2 -0.144971 0.140942 -1.02859 0.30369778
#> X1 0.468274 0.196060 2.38842 0.01693926 *
#> X2 -0.115913 0.145800 -0.79501 0.42662495
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 6.990856 on 9994 degrees of freedom
#> Number of observations: 10000 Degrees of Freedom: 9994
#> SSR: 488427.398407 MSE: 48.872063 Root MSE: 6.990856
#> Multiple R-Squared: -49.208252 Adjusted R-Squared: -49.233372
#>
#>
#> 2SLS estimates for 'supply' (equation 2)
#> Model Formula: Q ~ P + Xs1 + X1 + X2
#> <environment: 0x562e83c11650>
#> Instruments: ~Xd1 + Xd2 + X1 + X2 + Xs1
#> <environment: 0x562e83c11650>
#>
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -2.7883417 3.9483795 -0.70620 0.480081
#> P 0.4476886 0.1843561 2.42839 0.015184 *
#> Xs1 0.8150032 0.1302455 6.25744 4.0739e-10 ***
#> X1 -0.3225859 0.1269523 -2.54100 0.011069 *
#> X2 0.1349937 0.0747959 1.80483 0.071132 .
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 3.306714 on 9995 degrees of freedom
#> Number of observations: 10000 Degrees of Freedom: 9995
#> SSR: 109288.898698 MSE: 10.934357 Root MSE: 3.306714
#> Multiple R-Squared: -10.234432 Adjusted R-Squared: -10.238928
bbmle::summary(eqmdl_est)
#> Maximum likelihood estimation
#>
#> Call:
#> `bbmle::mle2`(list(method = "BFGS", control = list(REPORT = 10,
#> maxit = 10000, reltol = 1e-06), skip.hessian = FALSE, start = c(D_P = 0.0231239615913565,
#> D_CONST = 7.53375095184334, D_Xd1 = 0.140015230368245, D_Xd2 = -0.0737970096786045,
#> D_X1 = -0.074691417704378, D_X2 = 0.0462502352837326, S_P = 0.0248455188388157,
#> S_CONST = 6.24286219183355, S_Xs1 = 0.558355600251176, S_X1 = -0.0743221338857006,
#> S_X2 = 0.055148632519299, D_VARIANCE = 1, S_VARIANCE = 1, RHO = 0
#> ), minuslogl = function (...)
#> minus_log_likelihood(object, ...), gr = function (...)
#> gradient(object, ...)))
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(z)
#> D_P 0.315927 0.091374 3.4575 0.0005452 ***
#> D_CONST 1.719435 1.106403 1.5541 0.1201661
#> D_Xd1 0.046123 0.129963 0.3549 0.7226719
#> D_Xd2 -0.026924 0.122840 -0.2192 0.8265120
#> D_X1 -0.225090 0.941187 -0.2392 0.8109846
#> D_X2 0.123374 0.873290 0.1413 0.8876532
#> S_P 0.463977 0.040523 11.4497 < 2.2e-16 ***
#> S_CONST -0.652257 3.363514 -0.1939 0.8462376
#> S_Xs1 -0.224884 0.212250 -1.0595 0.2893618
#> S_X1 -0.301697 1.317718 -0.2290 0.8189044
#> S_X2 0.157299 1.269605 0.1239 0.9013977
#> D_VARIANCE 5.623492 2.911855 1.9312 0.0534534 .
#> S_VARIANCE 11.712092 1.003949 11.6660 < 2.2e-16 ***
#> RHO 0.991965 0.012483 79.4673 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> -2 log L: 95759.78
bbmle::summary(bsmdl_est)
#> Maximum likelihood estimation
#>
#> Call:
#> `bbmle::mle2`(list(control = list(REPORT = 10, maxit = 10000,
#> reltol = 1e-06), method = "BFGS", skip.hessian = FALSE, start = c(D_P = 0.0231239615913565,
#> D_CONST = 7.53375095184334, D_Xd1 = 0.140015230368245, D_Xd2 = -0.0737970096786045,
#> D_X1 = -0.074691417704378, D_X2 = 0.0462502352837326, S_P = 0.0248455188388157,
#> S_CONST = 6.24286219183355, S_Xs1 = 0.558355600251176, S_X1 = -0.0743221338857006,
#> S_X2 = 0.055148632519299, D_VARIANCE = 1, S_VARIANCE = 1, RHO = 0
#> ), minuslogl = function (...)
#> minus_log_likelihood(object, ...), gr = function (...)
#> gradient(object, ...)))
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(z)
#> D_P -0.0676615 0.0053178 -12.7235 < 2.2e-16 ***
#> D_CONST 9.0991117 0.0234794 387.5354 < 2.2e-16 ***
#> D_Xd1 0.3051360 0.0405738 7.5205 5.456e-14 ***
#> D_Xd2 -0.1839963 0.0761052 -2.4177 0.01562 *
#> D_X1 0.5776875 0.0139506 41.4095 < 2.2e-16 ***
#> D_X2 -0.1443290 0.1024587 -1.4087 0.15894
#> S_P 0.0813754 0.2122468 0.3834 0.70142
#> S_CONST 5.4182457 0.1672661 32.3930 < 2.2e-16 ***
#> S_Xs1 0.9298673 0.5269122 1.7647 0.07761 .
#> S_X1 -0.5213550 0.3845421 -1.3558 0.17517
#> S_X2 0.2025852 0.5065630 0.3999 0.68921
#> D_VARIANCE 0.9286177 0.0364390 25.4842 < 2.2e-16 ***
#> S_VARIANCE 0.9959581 0.0049565 200.9406 < 2.2e-16 ***
#> RHO 0.1731088 0.0068595 25.2363 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> -2 log L: 26189.5
bbmle::summary(damdl_est)
#> Maximum likelihood estimation
#>
#> Call:
#> `bbmle::mle2`(list(control = list(REPORT = 10, maxit = 10000,
#> reltol = 1e-06), method = "BFGS", skip.hessian = FALSE, start = c(D_P = -0.00260947112358515,
#> D_CONST = 7.98130444023755, D_Xd1 = 0.15954441702268, D_Xd2 = -0.0956278531130884,
#> D_X1 = 0.0454572982786684, D_X2 = 0.0215741337521343, S_P = 0.000425847047005336,
#> S_CONST = 6.8876653018125, S_Xs1 = 0.467154949725634, S_X1 = 0.0442638269176111,
#> S_X2 = 0.0274612448510507, P_DIFF = 1, D_VARIANCE = 1, S_VARIANCE = 1,
#> RHO = 0), minuslogl = function (...)
#> minus_log_likelihood(object, ...), gr = function (...)
#> gradient(object, ...)))
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(z)
#> D_P -0.100366 0.145267 -0.6909 0.489624
#> D_CONST 12.327107 6.467643 1.9060 0.056655 .
#> D_Xd1 0.151130 0.530098 0.2851 0.775569
#> D_Xd2 -0.098899 0.497777 -0.1987 0.842513
#> D_X1 0.602814 1.038098 0.5807 0.561449
#> D_X2 -0.099291 0.689958 -0.1439 0.885572
#> S_P 0.001214 0.040901 0.0297 0.976321
#> S_CONST 6.868130 2.174538 3.1584 0.001586 **
#> S_Xs1 0.469062 0.451740 1.0383 0.299110
#> S_X1 0.043372 0.458715 0.0946 0.924672
#> S_X2 0.026985 0.445808 0.0605 0.951733
#> P_DIFF 0.609389 0.840360 0.7252 0.468359
#> D_VARIANCE 1.686571 2.516242 0.6703 0.502683
#> S_VARIANCE 0.797918 0.280988 2.8397 0.004516 **
#> RHO 0.672593 0.554509 1.2130 0.225149
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> -2 log L: 48414.93
bbmle::summary(samdl_est)
#> Maximum likelihood estimation
#>
#> Call:
#> `bbmle::mle2`(list(control = list(REPORT = 10, maxit = 10000,
#> reltol = 1e-06), method = "BFGS", skip.hessian = FALSE, start = c(D_P = -0.00260947112358515,
#> D_CONST = 7.98130444023755, D_Xd1 = 0.15954441702268, D_Xd2 = -0.0956278531130884,
#> D_X1 = 0.0454572982786684, D_X2 = 0.0215741337521343, S_P = 0.000425847047005336,
#> S_CONST = 6.8876653018125, S_Xs1 = 0.467154949725634, S_X1 = 0.0442638269176111,
#> S_X2 = 0.0274612448510507, P_DIFF = 1, P_CONST = 8.28009900264685,
#> P_Xp1 = -0.013207398816623, D_VARIANCE = 1, S_VARIANCE = 1, P_VARIANCE = 1,
#> RHO_DS = 0, RHO_DP = 0, RHO_SP = 0), minuslogl = function (...)
#> minus_log_likelihood(object, ...), gr = function (...)
#> gradient(object, ...)))
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(z)
#> D_P -0.0971316 0.0943072 -1.0299 0.303034
#> D_CONST 9.7139866 3.5971067 2.7005 0.006924 **
#> D_Xd1 0.2950376 0.5918948 0.4985 0.618158
#> D_Xd2 -0.1722320 0.5931622 -0.2904 0.771539
#> D_X1 0.5641836 0.7266000 0.7765 0.437471
#> D_X2 -0.0869383 0.5951835 -0.1461 0.883866
#> S_P 0.0989968 0.1171670 0.8449 0.398155
#> S_CONST 5.1636578 3.4173140 1.5110 0.130781
#> S_Xs1 0.9380370 0.7764735 1.2081 0.227019
#> S_X1 -0.5153828 0.8034774 -0.6414 0.521237
#> S_X2 0.1660077 0.6134594 0.2706 0.786692
#> P_DIFF 1.1852181 0.7435204 1.5941 0.110922
#> P_CONST 3.2090705 2.2336752 1.4367 0.150810
#> P_Xp1 0.7695691 0.7074431 1.0878 0.276676
#> D_VARIANCE 0.9769727 0.8059301 1.2122 0.225424
#> S_VARIANCE 1.0493231 0.9984562 1.0509 0.293284
#> P_VARIANCE 0.9399843 1.5106009 0.6223 0.533772
#> RHO_DS 0.0389034 1.3307039 0.0292 0.976677
#> RHO_DP 0.0029079 1.0359008 0.0028 0.997760
#> RHO_SP 0.0013893 1.0251445 0.0014 0.998919
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> -2 log L: 46400.96
The estimated demanded and supplied quantities can be calculated per observation.
market <- cbind(
demand = get_demanded_quantities(bsmdl, bsmdl_est@coef)[, 1],
supply = get_supplied_quantities(bsmdl, bsmdl_est@coef)[, 1]
)
summary(market)
#> demand supply
#> Min. : 7.133 Min. : 6.099
#> 1st Qu.: 8.625 1st Qu.: 8.078
#> Median : 9.050 Median : 8.664
#> Mean : 9.075 Mean : 8.644
#> 3rd Qu.: 9.520 3rd Qu.: 9.220
#> Max. :11.087 Max. :11.221
The package offers also basic aggregation functionality.