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

See also

numDeriv::grad

likelihood_contr_model$get_loglik

numDeriv::hessian

likelihood_contr_model$get_loglik

Public fields

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

Methods


Method new()

Initializes a new instance of the class

Usage

likelihood_contr_model$new(
  obs_type,
  logliks = NULL,
  scores = NULL,
  hess_logliks = NULL,
  assumptions = c("iid")
)

Arguments

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)

Returns

A new likelihood_contr_model object


Method loglik()

Computes the log-likelihood of the model.

Usage

likelihood_contr_model$loglik(df, par, ...)

Arguments

df

dataframe for computation

par

parameters for computation

...

additional arguments

Returns

The total log-likelihood


Method score()

Computes the score of the model.

Usage

likelihood_contr_model$score(df, par, ...)

Arguments

df

dataframe for computation

par

parameters for computation

...

additional arguments

Returns

The total score


Method hess_loglik()

Computes the Hessian of the log-likelihood.

Usage

likelihood_contr_model$hess_loglik(df, par, ...)

Arguments

df

dataframe for computation

par

parameters for computation

...

additional arguments

Returns

The Hessian of the log-likelihood


Method 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.

Usage

likelihood_contr_model$get_loglik(type)

Arguments

type

observation type

Returns

The loglikelihood contribution for an observation


Method 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.

Usage

likelihood_contr_model$get_score(type)

Arguments

type

observation type

Returns

The score for an observation


Method 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.

Usage

likelihood_contr_model$get_hess_loglik(type)

Arguments

type

observation type

Returns

The Hessian of the log-likelihood for an observation


Method clone()

The objects of this class are cloneable with this method.

Usage

likelihood_contr_model$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.