Learn R Programming

iprior (version 0.6.5)

logLik: Obtain the log-likelihood and deviance of an ipriorMod or ipriorKernel object

Description

This function calculates the log-likelihood value or deviance (twice the negative log-likelihood) for I-prior models. It works for both ipriorMod and ipriorKernel class objects.

Usage

# S3 method for ipriorMod
logLik(object, theta = NULL, ...)

# S3 method for ipriorKernel logLik(object, theta = NULL, ...)

# S3 method for ipriorMod deviance(object, theta = NULL, ...)

# S3 method for ipriorKernel deviance(object, theta = NULL, ...)

Arguments

object

An object of class ipriorMod or ipriorKernel.

theta

(optional) Evaluates the log-likelihood at theta which is of the form theta = c(lambda, psi).

...

No further arguments required, so this is not used for ipriorMod or ipriorKernel class objects.

Details

For ipriorKernel objects, the log-likelihood or deviance is calculated at random parameter values by default. This is because it uses the (random) initial values for the parameters from the EM algorithm. For ipriorMod objects, the default value is the last obtained set of parameter values of the EM algorithm. If the model has converged, then this should be the maximum likelihood (ML) value.

For both types of object, it is possible to supply a parameter value at which to calculate the log-likelihood/deviance. This makes estimating an I-prior model more flexible, by first loading the variables into an ipriorKernel object, and then using an optimiser such as optim. Any other optimiser that can implement bounded constraints can be used. The only constraint requirement is on the parameter psi which has to be greater than zero (although setting the constraint to a small number such as 1e-9 will avoid an ill conditioned variance).

Direct maximisation of the log-likelihood of I-prior models can be unreliable some times, but other times it could also lead to a better set of parameters if the EM does not converge fully. Perhaps in the future, this package can make use of both methods combined as standard.

As a side note, the ML estimate for the intercept of an I-prior model is the mean of the responses y, and therefore not included as a parameter of the log-likelihood/deviance function.

Examples

Run this code
mod.iprior <- iprior(stack.loss ~ ., data=stackloss)
logLik(mod.iprior)

# Using optim to find ML estimates
optim(abs(rnorm(4)), deviance, object = mod.iprior,
      method="L-BFGS-B", lower = c(-Inf, -Inf, -Inf, 1e-9))
coef(mod.iprior)
deviance(mod.iprior)

Run the code above in your browser using DataLab