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 = 405.737 eps = 0.128969
GAMLSS-RS iteration 2: Global Deviance = 405.7368 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.05774 10.06075
2 58.98303 18.52920
3 96.14450 34.11606
## mean of the response distribution
predict(m, newdata = nd, type = "response") 1 2 3
23.05774 58.98303 96.14450
## model parameter(s)
predict(m, newdata = nd) mu sigma
1 23.05774 10.06075
2 58.98303 18.52920
3 96.14450 34.11606
predict(m, newdata = nd, model = "sigma") 1 2 3
10.06075 18.52920 34.11606
predict(m, newdata = nd, model = "sigma", drop = FALSE) sigma
1 10.06075
2 18.52920
3 34.11606
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma") (Intercept) s(speed)
1 2.63843 -0.3297884
2 2.63843 0.2809179
3 2.63843 0.8913382
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)") s(speed)
1 -0.3297884
2 0.2809179
3 0.8913382
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200) mu.fit mu.se sigma.fit sigma.se
1 23.05774 4.928374 1.097054e+01 4.779833e+00
2 58.98303 12.886448 2.394928e+01 1.854323e+01
3 96.14450 101.969791 4.156110e+09 5.877232e+10