I'm trying to run different forecast modeling methods on a monthly tsibble dataset. Its head() looks like:
# A tsibble: 6 x 2 [1M]
month total
<mth> <dbl>
1 2000 Jan 104.
2 2000 Feb 618.
3 2000 Mar 1005.
4 2000 Apr 523.
5 2000 May 1908.
6 2000 Jun 1062.
and has a structure of:
tsibble [212 x 2] (S3: tbl_ts/tbl_df/tbl/data.frame)
$ month: mth [1:212] 2000 Jan, 2000 Feb, 2000 Mar, 2000 Apr, 2000 May, 2000 Jun, 2000 Jul, 2000 Aug, 2000 Sep, 2000 Oct, 2000 Nov...
$ total: num [1:212] 104 618 1005 523 1908 ...
- attr(*, "key")= tibble [1 x 1] (S3: tbl_df/tbl/data.frame)
..$ .rows: list<int> [1:1]
.. ..$ : int [1:212] 1 2 3 4 5 6 7 8 9 10 ...
.. ..@ ptype: int(0)
- attr(*, "index")= chr "month"
..- attr(*, "ordered")= logi TRUE
- attr(*, "index2")= chr "month"
- attr(*, "interval")= interval [1:1] 1M
..@ .regular: logi TRUE
The dataset is monthly from 2000/01 to 2017/08 with no missing values or time periods. I'm trying to run a model such as:
df %>%
model(STL(total ~ season(window=9),robust=T)) %>%
components() %>% autoplot()
fit <- df %>%
model(ANN =ETS(total ~ error("A") + trend("A") + season()))
But for any type of model I try to run I get the exact same error each time. I'm looking for suggestions to correct the structure of the tsibble to allow these model functions to work.
Error in UseMethod("model") :
no applicable method for 'model' applied to an object of class "c('tbl_ts', 'tbl_df', 'tbl', 'data.frame')"
EDIT: Including reproducible example:
a = c(sample(1:1000,212))
df.ts <- ts(a, start=c(2000,1),end=c(2017,8),frequency=12)
df <- df.ts %>% as_tsibble()
As both Russ Conte and Rob Hyndman found there's nothing inherently wrong with the example code being used.
I believe there was an overlapping issue between two packages, as my issue was resolved upon removing and reinstalling the forecasting packages.