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.3647 eps = 0.125474     
GAMLSS-RS iteration  2: Global Deviance = 406.1777 eps = 0.002913     
GAMLSS-RS iteration  3: Global Deviance = 406.147 eps = 0.000075     
GAMLSS-RS iteration  4: Global Deviance = 406.1463 eps = 0.000001     
## 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.30817 10.08972
2 58.58058 18.62469
3 93.85473 34.37062
## mean of the response distribution
predict(m, newdata = nd, type = "response")
       1        2        3 
23.30817 58.58058 93.85473 
## model parameter(s)
predict(m, newdata = nd)
        mu    sigma
1 23.30817 10.08972
2 58.58058 18.62469
3 93.85473 34.37062
predict(m, newdata = nd, model = "sigma")
       1        2        3 
10.08972 18.62469 34.37062 
predict(m, newdata = nd, model = "sigma", drop = FALSE)
     sigma
1 10.08972
2 18.62469
3 34.37062
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma")
  (Intercept)   s(speed)
1    2.642528 -0.3310114
2    2.642528  0.2819596
3    2.642528  0.8946739
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)")
    s(speed)
1 -0.3310114
2  0.2819596
3  0.8946739