data("salmonella.agona")
## convert to sts class
salmonella <- disProg2sts(salmonella.agona)
## fit a basic model
fit0 <- hhh4(salmonella,
list(ar = list(f = ~1), end = list(f = addSeason2formula(~1))))
## the same, updating the minimal endemic-only model via 'S' (with a warning):
fit0.2 <- update(hhh4(salmonella), # has no AR component
S = list(ar = 0, end = 1))
local({
fit0$control$start <- fit0.2$control$start <- NULL # obviously different
stopifnot(all.equal(fit0, fit0.2))
})
## multiple updates: Poisson -> NegBin1, more harmonics
fit1 <- update(fit0, family = "NegBin1", S = list(end=2, ar=2))
## compare fits
AIC(fit0, fit1)
opar <- par(mfrow=c(2,2))
plot(fit0, type="fitted", names="fit0", par.settings=NULL)
plot(fit1, type="fitted", names="fit1", par.settings=NULL)
plot(fit0, fit1, type="season", components=c("end", "ar"), par.settings=NULL)
par(opar)
Run the code above in your browser using DataLab