The fable.tscount package allows tsglm()
models from the {tscount}
package to be used in a tidy workflow with the modelling interface of ‘fabletools’. This extends ‘tscount’ to provide enhanced model specification and management, performance evaluation methods, and model combination tools.
You can install the development version from GitHub
# install.packages("remotes")
remotes::install_github("mitchelloharawild/fable.tscount")
library(fable.tscount)
#> Loading required package: fabletools
library(tsibble)
#>
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, union
ecoli <- tsibble(
week = yearweek(paste0(tscount::ecoli$year, " W", tscount::ecoli$week)),
cases = tscount::ecoli$cases,
index = "week"
)
ecoli
#> # A tsibble: 646 x 2 [1W]
#> week cases
#> <week> <dbl>
#> 1 2001 W01 5
#> 2 2001 W02 7
#> 3 2001 W03 17
#> 4 2001 W04 18
#> 5 2001 W05 10
#> 6 2001 W06 8
#> 7 2001 W07 10
#> 8 2001 W08 9
#> 9 2001 W09 13
#> 10 2001 W10 16
#> # … with 636 more rows
fit <- ecoli %>%
model(TSCOUNT(cases))
fit
#> # A mable: 1 x 1
#> `TSCOUNT(cases)`
#> <model>
#> 1 <TSCOUNT>
report(fit)
#> Series: cases
#> Model: TSCOUNT
#>
#> Coefficients:
#> Estimate Std.Error CI(lower) CI(upper)
#> (Intercept) 20.3 0.177 20 20.7
#> Standard errors and confidence intervals (level = 95 %) obtained
#> by normal approximation.
#>
#> Link function: identity
#> Distribution family: poisson
#> Number of coefficients: 1
#> Log-likelihood: -2758.72
#> AIC: 5519.441
#> BIC: 5523.911
#> QIC: 5519.441
ecoli %>%
model(TSCOUNT(cases)) %>%
generate(times = 10)
#> # A tsibble: 1,040 x 4 [1W]
#> # Key: .model, .rep [10]
#> .model .rep week .sim
#> <chr> <chr> <week> <dbl>
#> 1 TSCOUNT(cases) 1 2013 W21 20
#> 2 TSCOUNT(cases) 1 2013 W22 23
#> 3 TSCOUNT(cases) 1 2013 W23 20
#> 4 TSCOUNT(cases) 1 2013 W24 16
#> 5 TSCOUNT(cases) 1 2013 W25 13
#> 6 TSCOUNT(cases) 1 2013 W26 26
#> 7 TSCOUNT(cases) 1 2013 W27 21
#> 8 TSCOUNT(cases) 1 2013 W28 30
#> 9 TSCOUNT(cases) 1 2013 W29 22
#> 10 TSCOUNT(cases) 1 2013 W30 17
#> # … with 1,030 more rows
ecoli %>%
model(TSCOUNT(cases)) %>%
forecast() %>%
autoplot(ecoli)
Please note that the fable.tscount project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.