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: model parameter(s) for all model parts
predict(m, newdata = nd) mu sigma
1 23.05774 10.06075
2 58.98303 18.52920
3 96.14450 34.11606
## additive predictors on the link scale
predict(m, newdata = nd, type = "link") mu sigma
1 23.05774 2.308642
2 58.98303 2.919348
3 96.14450 3.529768
## 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, 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
## predict quantiles
quantile(m, newdata = nd, probs = c(0.1, 0.5, 0.9)) 10% 50% 90%
1 10.16437 23.05774 35.95111
2 35.23691 58.98303 82.72916
3 52.42302 96.14450 139.86599
## standard errors
predict(m, newdata = nd, se.fit = TRUE, R = 200) mu.fit mu.se sigma.fit sigma.se
1 23.05774 1.908156 10.18556 1.619731
2 58.98303 3.459757 18.77165 3.062022
3 96.14450 8.981025 36.24582 12.975020