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.0254 eps = 0.130497
GAMLSS-RS iteration 2: Global Deviance = 404.935 eps = 0.000223
GAMLSS-RS iteration 3: Global Deviance = 404.9289 eps = 0.000015
GAMLSS-RS iteration 4: Global Deviance = 404.9283 eps = 0.000001
## new data for predictions
nd <- data.frame(speed = c(10, 20, 30))
## default: additive predictors (on link scale) for all parameters
predict(m, newdata = nd) mu sigma
1 22.28605 10.19378
2 60.96577 18.04439
3 108.89733 31.58630
## mean of the response distribution
predict(m, newdata = nd, type = "response") 1 2 3
22.28605 60.96577 108.89733
## predict parameter(s)
predict(m, newdata = nd) mu sigma
1 22.28605 10.19378
2 60.96577 18.04439
3 108.89733 31.58630
predict(m, newdata = nd, parameter = "sigma")[1] 10.19378 18.04439 31.58630
predict(m, newdata = nd, parameter = "sigma", drop = FALSE) sigma
1 10.19378
2 18.04439
3 31.58630
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", parameter = "sigma")[1] 2.6303504 2.6303504 2.6303504 -0.3085722 0.2624847 0.8223732
predict(m, newdata = nd, type = "terms", parameter = "sigma", terms = "s(speed)")[1] -0.3085722 0.2624847 0.8223732
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200) mu.fit mu.se sigma.fit sigma.se
1 22.28605 4.897917 1.126103e+01 5.055230e+00
2 60.96577 24.722882 4.016112e+01 6.643186e+01
3 108.89733 69.283589 1.071299e+22 1.429124e+23