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 = 406.1521 eps = 0.000088
GAMLSS-RS iteration 4: Global Deviance = 406.1491 eps = 0.000007
## 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.28681 10.10793
2 58.70678 18.59707
3 94.12851 34.20698
## mean of the response distribution
predict(m, newdata = nd, type = "response") 1 2 3
23.28681 58.70678 94.12851
## model parameter(s)
predict(m, newdata = nd) mu sigma
1 23.28681 10.10793
2 58.70678 18.59707
3 94.12851 34.20698
predict(m, newdata = nd, model = "sigma") 1 2 3
10.10793 18.59707 34.20698
predict(m, newdata = nd, model = "sigma", drop = FALSE) sigma
1 10.10793
2 18.59707
3 34.20698
## individual terms in additive predictor(s)
predict(m, newdata = nd, type = "terms", model = "sigma") (Intercept) s(speed)
1 2.642556 -0.3292360
2 2.642556 0.2804473
3 2.642556 0.8898731
predict(m, newdata = nd, type = "terms", model = "sigma", terms = "s(speed)") s(speed)
1 -0.3292360
2 0.2804473
3 0.8898731
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200) mu.fit mu.se sigma.fit sigma.se
1 23.28681 5.100319 1.111684e+01 5.087797e+00
2 58.70678 12.475172 2.382022e+01 1.763546e+01
3 94.12851 87.872462 8.784568e+06 1.204297e+08