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 = 405.8035 eps = 0.000921
GAMLSS-RS iteration 4: Global Deviance = 405.7928 eps = 0.000026
GAMLSS-RS iteration 5: Global Deviance = 405.7928 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.12533 10.04622
2 58.79229 18.57125
3 95.49447 34.32080
## mean of the response distribution
predict(m, newdata = nd, type = "response")
1 2 3
23.12533 58.79229 95.49447
## model parameter(s)
predict(m, newdata = nd)
mu sigma
1 23.12533 10.04622
2 58.79229 18.57125
3 95.49447 34.32080
predict(m, newdata = nd, model = "sigma")
1 2 3
10.04622 18.57125 34.32080
predict(m, newdata = nd, model = "sigma", drop = FALSE)
sigma
1 10.04622
2 18.57125
3 34.32080
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma")
(Intercept) s(speed)
1 2.63899 -0.3317927
2 2.63899 0.2826252
3 2.63899 0.8967621
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)")
s(speed)
1 -0.3317927
2 0.2826252
3 0.8967621