library("gamlss2")
## location and scale vary with x,
## shape parameters remain constant
f <- dist ~ s(speed) | s(speed) | 1 | 1
## estimate model
m1 <- gamlss2(f, data = cars, family = BCT)
## total deviance
deviance(m1)
## observation-wise deviance contributions
di <- deviance(m1, sum = FALSE)
## the contributions sum to the total deviance
sum(di)
deviance(m1)
## compare two models
m2 <- gamlss2(dist ~ s(speed) | 1 | 1 | 1, data = cars, family = BCT)
deviance(m1, m2)
## compare observation-wise deviance contributions
di <- deviance(m1, m2, sum = FALSE)
head(di)
## deviance on new data
nd <- cars[1:5, ]
deviance(m1, newdata = nd)
deviance(m1, newdata = nd, sum = FALSE)Deviance of GAMLSS Models
Description
Extracts the deviance from fitted gamlss2 objects. By default, the total deviance is returned. Optionally, observation-wise deviance contributions are returned.
Usage
## S3 method for class 'gamlss2'
deviance(object, ..., newdata = NULL, sum = TRUE)
Arguments
object
|
An object of class “gamlss2”.
|
…
|
Optionally, further fitted gamlss2 objects.
|
newdata
|
An optional data frame in which to evaluate the deviance. If omitted, the deviance is evaluated for the data used to fit the model. |
sum
|
Should the observation-wise deviance contributions be summed? If TRUE, the default, the total deviance is returned. If FALSE, the individual deviance contributions are returned.
|
Details
The deviance of a fitted gamlss2 model is defined as minus twice the fitted log-likelihood,
\(-2 \log L.\)
If sum = TRUE, one deviance value is returned for each supplied model. If more than one model is supplied, the deviances are ordered increasingly.
If sum = FALSE, the function returns the observation-wise deviance contributions,
\(-2 \log f(y_i | \hat\theta_i),\)
where \(f()\) is the fitted probability density or probability mass function and \(\hat\theta_i\) denotes the fitted distribution parameters for observation \(i\). These values sum to the total deviance and are useful, for example, in cross-validation.
Value
If sum = TRUE, a numeric vector with the total deviance of the supplied model or models. If sum = FALSE, a numeric vector of observation-wise deviance contributions for one model, or a matrix with one column per model if several models are supplied.
See Also
gamlss2