library("gamlss2")
## fit heteroscedastic normal GAMLSS model
## stopping distance (ft) explained by speed (mph)
data("cars", package = "datasets")
<- gamlss2(dist ~ s(speed) | s(speed), data = cars, family = NO) m
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
<- data.frame(speed = c(10, 20, 30))
nd
## 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