Extracts the fitted log-likelihood from gamlss2 objects. Optionally, the log-likelihood can be evaluated on new data. Several fitted models can be supplied for comparison.
Usage
## S3 method for class 'gamlss2'
logLik(object, ..., newdata = NULL)
Arguments
object
An object of class “gamlss2”.
…
Optionally, further fitted gamlss2 objects.
newdata
An optional data frame in which to evaluate the log-likelihood. If omitted, the log-likelihood stored in the fitted model object is returned. If supplied, newdata must contain the response variable.
Details
For the original model data, logLik() returns the log-likelihood value stored in the fitted gamlss2 object. If newdata is supplied, the distribution parameters are first predicted for the observations in newdata; the response is then extracted from newdata and the log-likelihood is recomputed using the model family.
The returned object follows the usual logLik convention: it has class “logLik” and carries attributes “df” and “nobs”. The degrees of freedom are taken from the fitted model object, while the number of observations is either the number of observations used for fitting or the number of rows evaluated in newdata.
If more than one fitted model is supplied, a named list of “logLik” objects is returned. The list is ordered by decreasing log-likelihood.
Value
For a single model, an object of class “logLik”. For several supplied models, a named list of “logLik” objects, ordered by decreasing log-likelihood.
See Also
logLik, deviance.gamlss2, gamlss2
Examples
library("gamlss2")## fit two normal GAMLSS models## stopping distance (ft) explained by speed (mph)data("cars", package ="datasets")m1 <-gamlss2(dist ~ speed |1, data = cars, family = NO)
GAMLSS-RS iteration 1: Global Deviance = 413.1569 eps = 0.113040
GAMLSS-RS iteration 2: Global Deviance = 413.1569 eps = 0.000000
m2 <-gamlss2(dist ~ speed | speed, data = cars, family = NO)
GAMLSS-RS iteration 1: Global Deviance = 406.1491 eps = 0.128084
GAMLSS-RS iteration 2: Global Deviance = 406.1483 eps = 0.000001
## fitted log-likelihoodlogLik(m1)
'log Lik.' -206.5784 (df=3)
## attributes follow the usual logLik conventionll <-logLik(m1)attr(ll, "df")