Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fit multiple models for each time series #4

Open
ghost opened this issue Sep 27, 2017 · 0 comments
Open

How to fit multiple models for each time series #4

ghost opened this issue Sep 27, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 27, 2017

Hi,

I'm playing with sweep and I'm struggling in how to forecast multiple models for each time series in the tibble. I have read the vignettes and this topic it's treated separately and I haven't been able to merge both ideas.

Here is a reproducible example:

library(forecast)
library(tidyquant)
library(timetk)
library(sweep)

monthly_qty_by_cat2_ts <- bike_sales %>%
  mutate(order.month = as_date(as.yearmon(order.date))) %>%
  group_by(category.secondary, order.month) %>%
  summarise(total.qty = sum(quantity)) %>% 
  group_by(category.secondary) %>%
  nest(.key = "data.tbl") %>% 
  mutate(data.ts = map(.x       = data.tbl, 
                       .f       = tk_ts, 
                       select   = -order.month, 
                       start    = 2011,
                       freq     = 12))

# Time Series forecasting
monthly_qty_by_cat2_fit <- monthly_qty_by_cat2_ts %>%
  mutate(fit.ets = map(data.ts, ets))
monthly_qty_by_cat2_fit

# Output
# A tibble: 9 x 4
  category.secondary          data.tbl  data.ts   fit.ets
               <chr>            <list>   <list>    <list>
1 Cross Country Race <tibble [60 x 2]> <S3: ts> <S3: ets>
2         Cyclocross <tibble [60 x 2]> <S3: ts> <S3: ets>
3         Elite Road <tibble [60 x 2]> <S3: ts> <S3: ets>
4     Endurance Road <tibble [60 x 2]> <S3: ts> <S3: ets>
5           Fat Bike <tibble [58 x 2]> <S3: ts> <S3: ets>
6      Over Mountain <tibble [60 x 2]> <S3: ts> <S3: ets>
7              Sport <tibble [60 x 2]> <S3: ts> <S3: ets>
8              Trail <tibble [60 x 2]> <S3: ts> <S3: ets>
9         Triathalon <tibble [60 x 2]> <S3: ts> <S3: ets>

One solutions would be the following one but I belive that there exist a better way to do that

monthly_qty_by_cat2_fit <- monthly_qty_by_cat2_ts %>%
  mutate(fit.ets = map(data.ts, ets),
         fit.arima = map(data.ts, auto.arima),
         ...)

What I'm trying to do is forecast different models as it's done in the vignette SW02_Forecasting_Multiple_Models but here the list of models has the data "hardcoded" and then it's just executed with invoke_map.

How it could be modified to be able to forecast multiple models?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants