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.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
<- 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.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