model_likelihoods {markets} | R Documentation |
Model likelihoods and derivatives
Description
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 signature 'diseq_basic'
log_likelihood(object, parameters)
## S4 method for signature 'diseq_basic'
gradient(object, parameters)
## S4 method for signature 'diseq_basic,ANY,ANY'
scores(object, parameters)
## S4 method for signature 'diseq_deterministic_adjustment'
log_likelihood(object, parameters)
## S4 method for signature 'diseq_deterministic_adjustment'
gradient(object, parameters)
## S4 method for signature 'diseq_deterministic_adjustment,ANY,ANY'
scores(object, parameters)
## S4 method for signature 'diseq_directional'
log_likelihood(object, parameters)
## S4 method for signature 'diseq_directional'
gradient(object, parameters)
## S4 method for signature 'diseq_directional,ANY,ANY'
scores(object, parameters)
## S4 method for signature 'diseq_stochastic_adjustment'
log_likelihood(object, parameters)
## S4 method for signature 'diseq_stochastic_adjustment'
gradient(object, parameters)
## S4 method for signature 'diseq_stochastic_adjustment,ANY,ANY'
scores(object, parameters)
## S4 method for signature 'equilibrium_model'
log_likelihood(object, parameters)
## S4 method for signature 'equilibrium_model'
gradient(object, parameters)
## S4 method for signature 'equilibrium_model,ANY,ANY'
scores(object, parameters)
## S4 method for signature 'diseq_basic'
hessian(object, parameters)
## S4 method for signature 'diseq_directional'
hessian(object, parameters)
## S4 method for signature '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
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)))