This class encapsulates all necessary parts of a likelihood model. A likelihood_model should provide the following methods:
loglik
: computes the log-likelihood of the model
score
: computes the score of the model
hess_loglik
: computes the Hessian of the log-likelihood given
a data frame and parameters
fim
: computes the Fisher information matrix (expectation)
It provides methods for computing the log-likelihood, score, the Hessian of log-likelihood, and the Fisher information matrix (FIM).
It also allows for different likelihood contributions depending on the observation type of a row in the data frame. For example, if the data frame contains both exact and interval-censored observations, then the log-likelihood contributions for exact observations and interval-censored observations are computed separately and then summed up (assumes i.i.d. samples).
likelihood_contr_model$get_loglik
likelihood_contr_model$get_loglik
logliks
list of functions for computing log-likelihoods
scores
list of functions for computing scores
hess_logliks
list of functions for computing Hessians
obs_type
function that determines observation type
assumptions
list of assumptions made by the model
new()
Initializes a new instance of the class
likelihood_contr_model$new(
obs_type,
logliks = NULL,
scores = NULL,
hess_logliks = NULL,
assumptions = c("iid")
)
obs_type
function that determines observation type
logliks
list of functions for computing log-likelihoods
If an observation type does not have a log-likelihood dispatcher
specified here, then we lazily construct a log-likelihood for said
observation type by looking for a loglik.type
, where type
is the
observation type. If we cannot find a loglik.type
, then we throw
an error.
scores
list of functions for computing scores.
If an observation type does not have a score dispatcher specified
here, then we lazily construct a score for said observation
type using the following method:
(1) first, we look for a score.type
, where type
is the
observation type.
(2) if (1) fails, then we use a finite difference method given the
log-likelihood contribution for the observation type.
hess_logliks
list of functions for computing Hessians of the
log-likelihood given the observed data. If an observation type does
not have a Hessian dispatcher specified here, then we lazily
construct a Hessian for said observation type using the following
method:
(1) first, we look for a hess_loglik.type
, where type
is the
observation type.
(2) if (1) fails, then we use a finite difference method given the
log-likelihood contribution for the observation type.
assumptions
list of assumptions made by the model, default is c("iid""), which assumes iid observations (this assumption is always made for this class, which is why we can sum the log-likelihood contributions)
loglik()
Computes the log-likelihood of the model.
score()
Computes the score of the model.
hess_loglik()
Computes the Hessian of the log-likelihood.
get_loglik()
Gets the loglikelihood contribution for an observation of type
.
If the loglikelihood contribution for type
does not have a
corresponding method in the dispatcher, then we try to retrieve one
from loglik.type
, where type
is the observation type. If this
fails, then we throw an error.
get_score()
Gets the score for an observation of type
.
If the score for type
does not have a corresponding method in the
dispatcher, then we try to retrieve one from score.type
, where
type
is the observation type. If this fails, then we use a
finite difference method to compute the gradient of the
log-likelihood function for the observation type.
get_hess_loglik()
Gets the Hessian of the log-likelihood for an observation of type
.
If the Hessian of the log-likelihood for type
does not have a
corresponding method in the dispatcher, then we try to retrieve one
from hess_loglik.type
, where type
is the observation type. If
this fails, then we use a finite difference method to compute the
Hessian of the log-likelihood function for the observation type.