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 = 407.3647 eps = 0.125474
GAMLSS-RS iteration 2: Global Deviance = 406.1879 eps = 0.002888
GAMLSS-RS iteration 3: Global Deviance = 405.7966 eps = 0.000963
GAMLSS-RS iteration 4: Global Deviance = 405.7908 eps = 0.000014
GAMLSS-RS iteration 5: Global Deviance = 405.7908 eps = 0.000000
## new data for predictions
nd <- data.frame(speed = c(10, 20, 30))
## default: additive predictors (on link scale) for all model parameters
predict(m, newdata = nd) mu sigma
1 23.11757 10.05004
2 58.82097 18.56457
3 95.57069 34.28308
## mean of the response distribution
predict(m, newdata = nd, type = "response") 1 2 3
23.11757 58.82097 95.57069
## model parameter(s)
predict(m, newdata = nd) mu sigma
1 23.11757 10.05004
2 58.82097 18.56457
3 95.57069 34.28308
predict(m, newdata = nd, model = "sigma") 1 2 3
10.05004 18.56457 34.28308
predict(m, newdata = nd, model = "sigma", drop = FALSE) sigma
1 10.05004
2 18.56457
3 34.28308
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma") (Intercept) s(speed)
1 2.63897 -0.3313934
2 2.63897 0.2822851
3 2.63897 0.8956823
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)") s(speed)
1 -0.3313934
2 0.2822851
3 0.8956823
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200) mu.fit mu.se sigma.fit sigma.se
1 23.11757 4.936673 1.094468e+01 4.725302e+00
2 58.82097 12.621997 2.381664e+01 1.813702e+01
3 95.57069 98.059417 1.209940e+10 1.711069e+11