All models are estimated using full information maximum likelihood. The
equilibrium_model
can also be estimated using two-stage
least squares. The maximum likelihood estimation is based on
optim
. If no starting values are provided, the function uses
linear regression estimates as initializing values. The default optimization method is
BFGS. For other alternatives see optim
. The implementation of
the two-stage least square estimation of the equilibrium_model
is based on lm
.
Usage
estimate(object, ...)
# S4 method for market_model
estimate(
object,
gradient = "calculated",
hessian = "calculated",
standard_errors = "homoscedastic",
...
)
# S4 method for equilibrium_model
estimate(object, method = "BFGS", optimizer = "optim", ...)
Arguments
- object
A model object.
- ...
Additional parameter used in the model's estimation. These are passed further down to the optimization call. For the
equilibrium_model
model, the parameters are passed tolm
, if the method is set to2SLS
, or tooptim
for any other method. For the rest of the models, the parameters are passed tooptim
.- gradient
One of two potential options:
"numerical"
and"calculated"
. By default, all the models are estimated using the analytic expressions of their likelihoods' gradients.- hessian
One of three potential options:
"skip"
,"numerical"
, and"calculated"
. The default is to use the"calculated"
Hessian for the models that expressions are available and the"numerical"
Hessian in other cases. Calculated Hessian expressions are available for the basic and directional models.- standard_errors
One of three potential options:
"homoscedastic"
,"heteroscedastic"
, or a vector with variables names for which standard error clusters are to be created. The default value is"homoscedastic"
. If the option"heteroscedastic"
is passed, the variance-covariance matrix is calculated using heteroscedasticity adjusted (Huber-White) standard errors. If a vector with variable names is supplied, the variance-covariance matrix is calculated by grouping the score matrix based on the passed variables.- method
A string specifying the estimation method. When the passed value is among
"Nelder-Mead"
,"BFGS"
,"CG"
,"L-BFGS-B"
,"SANN"
, and"Brent"
, the model is estimated using full information maximum likelihood based onoptim
functionality. When"2SLS"
is supplied, the model is estimated using two-stage least squares vialm
. In this case, the function returns a list containing the first and second stage estimates. The default value is"BFGS"
.- optimizer
One of two options:
"optim"
,"gsl"
. The default value is"optim"
. If the option"gsl"
is set, the equilibrium likelihood is maximized usingGSL
.
Details
The likelihood of the equilibrium model can be optimized either by using optim
(the default option) or native
GSL
routines.
The caller can override the default behavior by setting the optimizer
argument
equal to "gsl"
, in which case GSL
routines are used. This does not
necessarily result to faster execution times. This functionality is primarily
intended for advanced usage. The optim
functionality is a fast,
analysis-oriented alternative, which is more suitable for most use case.
When optimizer = "gsl"
is used, the only available optimization method is BFGS.
Additionally, the caller needs to specify in the control list values for the
optimization step (step
), the objective's optimization tolerance
(objective_tolerance
), the gradient's optimization tolerance
(gradient_tolerance
, and the maximum allowed number of iterations (maxit
).
If the GSL
library is not available in the calling machine, the function
returns a trivial result list with convergence status set equal to -1. If the
C++17 execution policies
are available, the implementation of the optimization is parallelized.
Functions
estimate(market_model)
: Full information maximum likelihood estimation.estimate(equilibrium_model)
: Equilibrium model estimation.
Examples
# \donttest{
# initialize the model using the houses dataset
model <- new(
"diseq_deterministic_adjustment", # model type
subject = ID, time = TREND, quantity = HS, price = RM,
demand = RM + TREND + W + CSHS + L1RM + L2RM + MONTH,
supply = RM + TREND + W + L1RM + MA6DSF + MA3DHF + MONTH,
fair_houses(), # data
correlated_shocks = FALSE # let shocks be independent
)
# estimate the model object (BFGS is used by default)
fit <- estimate(model)
# estimate the model by specifying the optimization details passed to the optimizer.
fit <- estimate(model, control = list(maxit = 1e+6))
# summarize results
summary(fit)
#> Deterministic Adjustment Model for Markets in Disequilibrium:
#> Demand RHS : D_RM + D_TREND + D_W + D_CSHS + D_L1RM + D_L2RM
#> + D_MONTH
#> Supply RHS : S_RM + S_TREND + S_W + S_L1RM + S_MA6DSF +
#> S_MA3DHF + S_MONTH
#> Short Side Rule : HS = min(D_HS, S_HS)
#> Separation Rule : RM_DIFF analogous to (D_HS - S_HS)
#> Shocks : Independent
#> Nobs : 129
#> Sample Separation : Demand Obs = 18, Supply Obs = 111
#> Quantity Var : HS
#> Price Var : RM
#> Key Var(s) : ID, TREND
#> Time Var : TREND
#>
#> Maximum likelihood estimation:
#> Method : BFGS
#> Max Iterations : 1e+06
#> Convergence Status : success
#> Starting Values :
#> D_RM D_CONST D_TREND D_W D_CSHS D_L1RM D_L2RM
#> 7.528e-02 7.462e+01 2.432e+00 2.395e+00 -1.977e-02 1.512e-01 -3.291e-01
#> D_MONTH02 D_MONTH03 D_MONTH04 D_MONTH05 D_MONTH06 D_MONTH07 D_MONTH08
#> 2.918e+00 3.110e+01 6.173e+01 6.452e+01 5.819e+01 4.851e+01 4.744e+01
#> D_MONTH09 D_MONTH10 D_MONTH11 D_MONTH12 S_RM S_CONST S_TREND
#> 4.219e+01 4.566e+01 2.885e+01 8.548e+00 1.465e-01 -5.076e+01 -1.243e-01
#> S_W S_L1RM S_MA6DSF S_MA3DHF S_MONTH02 S_MONTH03 S_MONTH04
#> 2.669e+00 -8.889e-02 4.754e-02 4.554e-02 3.371e+00 3.254e+01 6.598e+01
#> S_MONTH05 S_MONTH06 S_MONTH07 S_MONTH08 S_MONTH09 S_MONTH10 S_MONTH11
#> 6.660e+01 5.605e+01 4.175e+01 4.719e+01 4.172e+01 4.892e+01 3.026e+01
#> S_MONTH12 RM_DIFF D_VARIANCE S_VARIANCE
#> 1.094e+01 -4.684e-16 1.960e+02 1.035e+02
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> D_RM -6.39287048 0.857591642 -7.454446 9.024631e-14 ***
#> D_CONST -20.16533253 0.060974564 -330.717127 0.000000e+00 ***
#> D_TREND -3.09530903 0.230919075 -13.404302 5.705752e-41 ***
#> D_W 2.77909898 1.886047698 1.473504 1.406152e-01
#> D_CSHS 0.02878931 0.002627855 10.955440 6.257341e-28 ***
#> D_L1RM 8.92812266 1.272736617 7.014902 2.301102e-12 ***
#> D_L2RM -2.48883659 0.778072698 -3.198720 1.380392e-03 **
#> D_MONTH02 17.94359360 0.028355163 632.815745 0.000000e+00 ***
#> D_MONTH03 28.55310947 0.031907690 894.866076 0.000000e+00 ***
#> D_MONTH04 78.00303909 0.025111880 3106.220640 0.000000e+00 ***
#> D_MONTH05 84.17025404 0.013734549 6128.359314 0.000000e+00 ***
#> D_MONTH06 82.50861671 0.008009769 10300.998283 0.000000e+00 ***
#> D_MONTH07 88.22174395 0.033884480 2603.603317 0.000000e+00 ***
#> D_MONTH08 52.40940637 0.068537233 764.685185 0.000000e+00 ***
#> D_MONTH09 49.40057986 0.014656650 3370.523264 0.000000e+00 ***
#> D_MONTH10 67.05086057 0.025068207 2674.736959 0.000000e+00 ***
#> D_MONTH11 24.50611800 0.020945815 1169.976811 0.000000e+00 ***
#> D_MONTH12 30.86396923 0.037121309 831.435376 0.000000e+00 ***
#> S_RM 0.46442865 0.254953913 1.821618 6.851296e-02 .
#> S_CONST -37.46456496 0.017747929 -2110.925994 0.000000e+00 ***
#> S_TREND -0.14554797 0.045456126 -3.201944 1.365036e-03 **
#> S_W 2.08578681 0.667580491 3.124397 1.781696e-03 **
#> S_L1RM -0.40511192 0.259778911 -1.559449 1.188902e-01
#> S_MA6DSF 0.04693627 0.004759294 9.862022 6.081192e-23 ***
#> S_MA3DHF 0.03455421 0.007455667 4.634624 3.575865e-06 ***
#> S_MONTH02 3.81910684 0.038878752 98.231209 0.000000e+00 ***
#> S_MONTH03 34.38727665 0.044938607 765.205672 0.000000e+00 ***
#> S_MONTH04 65.75523098 0.048451885 1357.124311 0.000000e+00 ***
#> S_MONTH05 67.60421681 0.006803688 9936.407793 0.000000e+00 ***
#> S_MONTH06 57.39161807 0.010350186 5544.984254 0.000000e+00 ***
#> S_MONTH07 43.90383859 0.094392783 465.118595 0.000000e+00 ***
#> S_MONTH08 49.34401811 0.033172074 1487.516806 0.000000e+00 ***
#> S_MONTH09 44.93630427 0.045704348 983.195391 0.000000e+00 ***
#> S_MONTH10 49.43637822 0.046764866 1057.126482 0.000000e+00 ***
#> S_MONTH11 32.80682646 0.010520109 3118.487203 0.000000e+00 ***
#> S_MONTH12 11.27185537 0.090967431 123.910890 0.000000e+00 ***
#> RM_DIFF 1.53371422 0.744837694 2.059125 3.948223e-02 *
#> D_VARIANCE 1295.13136810 0.008069301 160501.051989 0.000000e+00 ***
#> S_VARIANCE 107.76446554 0.007893424 13652.435294 0.000000e+00 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> -2 log L: 1724.665
# }
# \donttest{
# simulate an equilibrium model
model <- simulate_model(
"equilibrium_model", list(
# observed entities, observed time points
nobs = 500, tobs = 3,
# demand coefficients
alpha_d = -1.9, beta_d0 = 24.9, beta_d = c(2.3, -1.2), eta_d = c(2.0, -1.5),
# supply coefficients
alpha_s = .9, beta_s0 = 8.2, beta_s = c(3.3), eta_s = c(1.5, -2.2)
),
seed = 99
)
# maximize the model's log-likelihood
fit <- estimate(
model,
optimizer = "gsl", control = list(
step = 1e-2, objective_tolerance = 1e-8,
gradient_tolerance = 1e-2, maxit = 1e+3
)
)
summary(fit)
#> Equilibrium Model for Markets in Equilibrium:
#> Demand RHS : D_P + D_Xd1 + D_Xd2 + D_X1 + D_X2
#> Supply RHS : S_P + S_Xs1 + S_X1 + S_X2
#> Market Clearing : Q = D_Q = S_Q
#> Shocks : Correlated
#> Nobs : 1500
#> Sample Separation : Not Separated
#> Quantity Var : Q
#> Price Var : P
#> Key Var(s) : id, date
#> Time Var : date
#>
#> Maximum likelihood estimation:
#> Method : BFGS
#> Max Iterations : 1000
#> Convergence Status : failure (-1)
#> Starting Values :
#> D_P D_CONST D_Xd1 D_Xd2 D_X1 D_X2 S_P
#> -1.90357 24.92297 2.29870 -1.22392 1.97103 -1.47621 0.83976
#> S_CONST S_Xs1 S_X1 S_X2 D_VARIANCE S_VARIANCE RHO
#> 8.57600 3.21044 1.52915 -2.14210 1.10049 0.86999 0.04954
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> D_P NaN NaN NaN NaN
#> D_CONST NaN NaN NaN NaN
#> D_Xd1 NaN NaN NaN NaN
#> D_Xd2 NaN NaN NaN NaN
#> D_X1 NaN NaN NaN NaN
#> D_X2 NaN NaN NaN NaN
#> S_P NaN NaN NaN NaN
#> S_CONST NaN NaN NaN NaN
#> S_Xs1 NaN NaN NaN NaN
#> S_X1 NaN NaN NaN NaN
#> S_X2 NaN NaN NaN NaN
#> D_VARIANCE NaN NaN NaN NaN
#> S_VARIANCE NaN NaN NaN NaN
#> RHO NaN NaN NaN NaN
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> -2 log L: NaN
# }