Predict response distributions, parameters, additive predictors, terms, or response means from a gamlss2 model.
Usage
## S3 method for class 'gamlss2'
predict(object, parameter = NULL, newdata = NULL,
type = c("distribution", "parameter", "link", "response", "terms"),
terms = NULL, se.fit = FALSE, drop = TRUE, ...,
level = NULL, interval = c("none", "wald"), unconditional = FALSE)
Arguments
object
A gamlss2 model.
parameter
Distribution parameter name(s) or index(es), such as “mu” or “sigma”; defaults to all parameters.
newdata
Data frame for predictions; defaults to the fitted data.
type
“distribution” (default) returns distributions3 objects; “parameter” returns parameters on their natural scale; “link” returns additive predictors; “response” returns response means; “terms” returns individual additive terms. Specifying parameter without type selects “parameter”.
terms
Additive terms to include; defaults to all. Names are partially matched unless nogrep = TRUE is passed in ….
se.fit
For ordinary predictions, TRUE computes standard errors from coefficient draws; R in … sets the number of draws (default 200).
drop
Simplify the result when possible.
level
Numeric confidence level(s) between zero and one; supplying levels selects pointwise Wald intervals.
interval
“none” (default) returns ordinary predictions; “wald” returns analytic pointwise confidence intervals, at the 95% confidence level by default.
unconditional
If TRUE, include approximate smoothing-parameter uncertainty in Wald intervals and coefficient draws.
…
Further controls, including FUN, R, seed, and burnin for simulation.
Details
Coefficient draws stored in the fit are used when available; otherwise, draws use the full joint coefficient covariance. They approximate the coefficient sampling distribution and may give unreliable tails after nonlinear transformations. Simulation stops if a marginal 95% Gaussian interval for a log smoothing parameter spans a factor of 100 on the smoothing-parameter scale.
Wald intervals are approximate pointwise confidence intervals for fitted values, not prediction intervals for future observations. They are computed without simulation and may be asymmetric on transformed scales. They condition on fitted smoothing parameters by default and exclude model-selection uncertainty; see vcov.gamlss2.
Wald intervals support maximum-likelihood fits with linear terms and coefficient-linear mgcv smooths, but not nonlinear custom special terms. They cannot be combined with FUN, R, seed, or burnin. An indefinite joint information matrix or non-estimable coefficient causes an error rather than a working-information approximation.
Value
Ordinary predictions return a distribution object or values in the selected form. Term predictions are data frames or, for multiple parameters, lists of matrices. With se.fit = TRUE, fitted values and standard errors are returned. With FUN = identity, simulated distribution predictions form a list of distribution objects.
Wald predictions return fit, se.fit, lower, and upper. For multiple levels, lower and upper are lists named by confidence percentage (for example, “80%” and “95%”). fit and each bound retain the structure selected by parameter, terms, and drop; se.fit is shared across levels.
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.0352 eps = 0.130476
GAMLSS-RS iteration 2: Global Deviance = 405.6152 eps = 0.001432
GAMLSS-RS iteration 3: Global Deviance = 405.657 eps = 0.000102
GAMLSS-RS iteration 4: Global Deviance = 405.6596 eps = 0.000006
## new data for predictionsnd <-data.frame(speed =c(10, 20, 30))## default: a "distribution" objectd <-predict(m, newdata = nd)print(d)