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 = 405.766 eps = 0.003924
GAMLSS-RS iteration 3: Global Deviance = 405.7473 eps = 0.000045
GAMLSS-RS iteration 4: Global Deviance = 405.7473 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.02058 10.08716
2 59.13735 18.49146
3 96.53656 33.88827
## mean of the response distribution
predict(m, newdata = nd, type = "response")
1 2 3
23.02058 59.13735 96.53656
## model parameter(s)
predict(m, newdata = nd)
mu sigma
1 23.02058 10.08716
2 59.13735 18.49146
3 96.53656 33.88827
predict(m, newdata = nd, model = "sigma")
1 2 3
10.08716 18.49146 33.88827
predict(m, newdata = nd, model = "sigma", drop = FALSE)
sigma
1 10.08716
2 18.49146
3 33.88827
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma")
(Intercept) s(speed)
1 2.638535 -0.3272719
2 2.638535 0.2787743
3 2.638535 0.8845340
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)")
s(speed)
1 -0.3272719
2 0.2787743
3 0.8845340
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200)
mu.fit mu.se sigma.fit sigma.se
1 23.02058 4.954498 1.102496e+01 4.878271e+00
2 59.13735 13.160966 2.409469e+01 1.890208e+01
3 96.53656 104.926124 1.163849e+09 1.645647e+10