Skip to contents

Methods that calculate the likelihoods, scores, gradients, and Hessians of market models. The likelihood functions are based on Maddala and Nelson (1974) doi:10.2307/1914215 . The likelihoods, gradient, and Hessian expressions that the function uses are derived in Karapanagiotis (2020) doi:10.2139/ssrn.3525622 .

log_likelihood

Returns the log-likelihood. The function calculates the model's log likelihood by evaluating the log likelihood of each observation in the sample and summing the evaluation results.

gradient

Returns the gradient of the log-likelihood evaluated at the passed parameters.

hessian

Returns the hessian of the log-likelihood evaluated at the passed parameters.

scores

It calculates the gradient of the likelihood at the given parameter point for each observation in the sample. It, therefore, returns an n x k matrix, where n denotes the number of observations in the sample and k the number of estimated parameters. The ordering of the parameters is the same as the one that is used in the summary of the results. The method can be called either using directly a fitted model object, or by separately providing a model object and a parameter vector.

Usage

log_likelihood(object, parameters)

gradient(object, parameters)

hessian(object, parameters)

scores(object, parameters, fit)

# S4 method for class 'diseq_basic'
log_likelihood(object, parameters)

# S4 method for class 'diseq_basic'
gradient(object, parameters)

# S4 method for class 'diseq_basic,ANY,ANY'
scores(object, parameters)

# S4 method for class 'diseq_deterministic_adjustment'
log_likelihood(object, parameters)

# S4 method for class 'diseq_deterministic_adjustment'
gradient(object, parameters)

# S4 method for class 'diseq_deterministic_adjustment,ANY,ANY'
scores(object, parameters)

# S4 method for class 'diseq_directional'
log_likelihood(object, parameters)

# S4 method for class 'diseq_directional'
gradient(object, parameters)

# S4 method for class 'diseq_directional,ANY,ANY'
scores(object, parameters)

# S4 method for class 'diseq_stochastic_adjustment'
log_likelihood(object, parameters)

# S4 method for class 'diseq_stochastic_adjustment'
gradient(object, parameters)

# S4 method for class 'diseq_stochastic_adjustment,ANY,ANY'
scores(object, parameters)

# S4 method for class 'equilibrium_model'
log_likelihood(object, parameters)

# S4 method for class 'equilibrium_model'
gradient(object, parameters)

# S4 method for class 'equilibrium_model,ANY,ANY'
scores(object, parameters)

# S4 method for class 'diseq_basic'
hessian(object, parameters)

# S4 method for class 'diseq_directional'
hessian(object, parameters)

# S4 method for class 'missing,missing,market_fit'
scores(fit)

Arguments

object

A model object.

parameters

A vector of parameters at which the function is to be evaluated.

fit

A fitted model object.

Value

log_likelihood

The sum of the likelihoods evaluated for each observation.

gradient

The log likelihood's gradient.

hessian

The log likelihood's hessian.

scores

The score matrix.

Examples

# \donttest{
model <- simulate_model(
  "diseq_basic", list(
    # observed entities, observed time points
    nobs = 500, tobs = 3,
    # demand coefficients
    alpha_d = -0.9, beta_d0 = 8.9, beta_d = c(0.6), eta_d = c(-0.2),
    # supply coefficients
    alpha_s = 0.9, beta_s0 = 7.9, beta_s = c(0.03, 1.2), eta_s = c(0.1)
  ),
  seed = 7523
)

# estimate the model object (BFGS is used by default)
fit <- estimate(model)

# Calculate the score matrix
head(scores(model, coef(fit)))
#>            D_P     D_CONST        D_Xd1          D_X1        S_P     S_CONST
#> 1  0.122260422 -0.34811752  0.417340236 -0.3605332179  0.5466158 -1.55640326
#> 2 -0.743843382 -1.23910947  1.148249906 -1.4036189852 -0.1513030 -0.25204357
#> 3 -0.037446089 -0.04769418 -0.047007752 -0.0006108855 -0.0625768 -0.07970256
#> 4  0.002693132 -0.01690514  0.008471139  0.0192476350 -0.1587665  0.99659773
#> 5  0.088372742 -0.14821086  0.129232886 -0.0357887188  0.1360946 -0.22824566
#> 6  0.201806861  0.29613341 -0.271890840  0.1908639813  0.3212258  0.47137000
#>         S_Xs1       S_Xs2         S_X1  D_VARIANCE  S_VARIANCE         RHO
#> 1  1.35247639  0.20897526 -1.611912774  0.39852402  0.97800236 -0.03240626
#> 2 -0.05638665 -0.04213804 -0.285505964  0.42071759  0.25214455 -0.05403332
#> 3  0.07472583  0.12786917 -0.001020861  0.04798689 -0.47379627 -0.04437969
#> 4  1.33182296 -1.31959174 -1.134693567 -0.02317068  0.02313445 -0.08570107
#> 5  0.15303714  0.03443069 -0.055114852  0.08776477 -0.40012622 -0.13650416
#> 6  0.58471108 -0.50310081  0.303807511 -0.25698735 -0.24866134 -0.05187506
# }