Extracting Fitted or Predicted Parameters or Terms from gamlss2 Models

Description

Methods for gamlss2 model objects for extracting fitted (in-sample) or predicted (out-of-sample) parameters, terms, etc.

Usage

## S3 method for class 'gamlss2'
predict(object, parameter = NULL, newdata = NULL,
  type = c("parameter", "link", "response", "terms"), terms = NULL,
  se.fit = FALSE, drop = TRUE, exclude = NULL, ...)

Arguments

object model object of class gamlss2.
parameter character. Which parameters should be predicted? E.g., can be one or more of “mu”, “sigma” using the NO family. By default all parameters are included.
newdata data.frame. Optionally, a new data frame in which to look for variables with which to predict. If omitted, the original observations are used.
type character. Which type of prediction should be computed? Can be the full additive predictor(s) (“link”, before applying the link function(s)), the corresponding parameter (“parameter”, after applying the link function(s)), the individual terms of the additive predictor(s) (“terms”), or the corresponding mean of the response distribution (“response”).
terms character. Which of the terms in the additive predictor(s) should be included? By default all terms are included.
se.fit logical. Should standard errors for the predictions be included? Standard errors are computed by simulating from the approximate multivariate normal distribution of the maximum likelihood estimates. The number of simulations is controlled by the argument R, which defaults to R = 200, and can be passed via .
drop logical. Should the predictions be simplified to a vector if possible (TRUE) or always returned as a data.frame (FALSE)?
exclude character. Any terms named in this vector will be set to zero.
currently only used for catching what or model as an alias for parameter.

Details

Predictions for gamlss2 model objects are obtained in the following steps: First, the original data is extracted or some newdata is set up. Second, all of the terms in the additive predictors of all model parameters (“mu”, “sigma”, …) are computed. Third, the full additive predictor(s) are obtained by adding up all individual terms. Fourth, the parameter(s) are obtained from the additive predictor(s) by applying the inverse link function(s). In a final step, the mean of the associated probability distribution can be computed.

See also prodist.gamlss2 for setting up a full distributions3 object from which moments, probabilities, quantiles, or random numbers can be obtained.

Value

If drop = FALSE a data.frame. If drop = TRUE (the default), the data.frame might be simplified to a numeric vector, if possible.

See Also

predict, prodist.gamlss2

Examples

library("gamlss2")

## fit heteroscedastic normal GAMLSS model
## stopping distance (ft) explained by speed (mph)
data("cars", package = "datasets")
m <- gamlss2(dist ~ s(speed) | s(speed), data = cars, family = NO)
GAMLSS-RS iteration  1: Global Deviance = 405.0254 eps = 0.130497     
GAMLSS-RS iteration  2: Global Deviance = 404.935 eps = 0.000223     
GAMLSS-RS iteration  3: Global Deviance = 404.9289 eps = 0.000015     
GAMLSS-RS iteration  4: Global Deviance = 404.9283 eps = 0.000001     
## new data for predictions
nd <- data.frame(speed = c(10, 20, 30))

## default: additive predictors (on link scale) for all parameters
predict(m, newdata = nd)
         mu    sigma
1  22.28605 10.19378
2  60.96577 18.04439
3 108.89733 31.58630
## mean of the response distribution
predict(m, newdata = nd, type = "response")
        1         2         3 
 22.28605  60.96577 108.89733 
## predict parameter(s)
predict(m, newdata = nd)
         mu    sigma
1  22.28605 10.19378
2  60.96577 18.04439
3 108.89733 31.58630
predict(m, newdata = nd, parameter = "sigma")
[1] 10.19378 18.04439 31.58630
predict(m, newdata = nd, parameter = "sigma", drop = FALSE)
     sigma
1 10.19378
2 18.04439
3 31.58630
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", parameter = "sigma")
[1]  2.6303504  2.6303504  2.6303504 -0.3085722  0.2624847  0.8223732
predict(m, newdata = nd, type = "terms", parameter = "sigma", terms = "s(speed)")
[1] -0.3085722  0.2624847  0.8223732
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200)
     mu.fit     mu.se    sigma.fit     sigma.se
1  22.28605  4.897917 1.126103e+01 5.055230e+00
2  60.96577 24.722882 4.016112e+01 6.643186e+01
3 108.89733 69.283589 1.071299e+22 1.429124e+23