estimate {markets}R Documentation

Model estimation

Description

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 signature 'market_model'
estimate(
  object,
  gradient = "calculated",
  hessian = "calculated",
  standard_errors = "homoscedastic",
  ...
)

## S4 method for signature '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 to lm, if the method is set to 2SLS, or to optim for any other method. For the rest of the models, the parameters are passed to optim.

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 on optim functionality. When "2SLS" is supplied, the model is estimated using two-stage least squares via lm. 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 using GSL.

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.

Value

A market fit object holding the estimation result.

Functions

Examples


# 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)


# 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)


[Package markets version 1.1.5 Index]