library("gamlss2")
## seasonal variation of motorcycle counts at Sonnenberg/Harz
data("HarzTraffic", package = "gamlss2")
plot(bikes ~ yday, data = HarzTraffic)
## count distribution
barplot(table(HarzTraffic$bikes))
## negative binomial seasonal model using cyclic splines
<- gamlss2(bikes ~ s(yday, bs = "cc") | s(yday, bs = "cc"),
m data = HarzTraffic, family = NBI)
GAMLSS-RS iteration 1: Global Deviance = 10163.1249 eps = 0.148398
GAMLSS-RS iteration 2: Global Deviance = 10151.6273 eps = 0.001131
GAMLSS-RS iteration 3: Global Deviance = 10151.3662 eps = 0.000025
GAMLSS-RS iteration 4: Global Deviance = 10151.2887 eps = 0.000007
## visualize effects
plot(m)
## residual diagnostics
plot(m, which = "resid")
## fitted parameters for each day of the year
<- data.frame(yday = 1:365)
nd
## corresponding quantiles
<- quantile(m, newdata = nd, probs = c(0.05, 0.5, 0.95))
p
## visualization
plot(bikes ~ yday, data = HarzTraffic, pch = 19, col = gray(0.1, alpha = 0.3))
matplot(nd$yday, p, type = "l", lty = c(2, 1, 2), lwd = 2, col = 4, add = TRUE)