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, model = NULL, newdata = NULL,
  type = c("parameter", "link", "response", "terms"), terms = NULL,
  se.fit = FALSE, drop = TRUE, ...)

Arguments

object model object of class gamlss2.
model character. Which model part(s) should be predicted? Can be one or more of “mu”, “sigma”, etc. By default all model parts 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? (not implemented yet).
drop logical. Should the predictions be simplified to a vector if possible (TRUE) or always returned as a data.frame (FALSE)?
currently only used for catching what as an alias for model.

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 = 407.3541 eps = 0.125497     
GAMLSS-RS iteration  2: Global Deviance = 405.7146 eps = 0.004024     
GAMLSS-RS iteration  3: Global Deviance = 405.6978 eps = 0.000041     
GAMLSS-RS iteration  4: Global Deviance = 405.6976 eps = 0.000000     
## new data for predictions
nd <- data.frame(speed = c(10, 20, 30))

## default: additive predictors (on link scale) for all model parameters
predict(m, newdata = nd)
        mu    sigma
1 23.03912 10.06300
2 59.03607 18.51012
3 96.34896 33.95078
## mean of the response distribution
predict(m, newdata = nd, type = "response")
       1        2        3 
23.03912 59.03607 96.34896 
## model parameter(s)
predict(m, newdata = nd)
        mu    sigma
1 23.03912 10.06300
2 59.03607 18.51012
3 96.34896 33.95078
predict(m, newdata = nd, model = "sigma")
       1        2        3 
10.06300 18.51012 33.95078 
predict(m, newdata = nd, model = "sigma", drop = FALSE)
     sigma
1 10.06300
2 18.51012
3 33.95078
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma")
  (Intercept)   s(speed)
1    2.638039 -0.3291741
2    2.638039  0.2802782
3    2.638039  0.8868728
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)")
    s(speed)
1 -0.3291741
2  0.2802782
3  0.8868728