How to add extra variables to TSLM model

160 views Asked by At

I'm trying to add some extra variables in my model like below: No problem adding new values to my numeric variables, but when I try to add more variables I got an issue

library(fpp3)

google_2015 <- gafa_stock %>% 
filter(Symbol == "GOOG", year(Date) == 2015) %>% 
mutate(trading_day = row_number()) %>% 
update_tsibble(index = trading_day, regular = TRUE) %>% 
mutate(qt = quarter(Date)) %>% 
mutate(dow = as.factor(weekdays(Date)))

google_2015_stretch <- google_2015 %>% 
stretch_tsibble(.init = 3, .step = 1) %>% 
filter(.id != max(.id))

fit_cv <- google_2015_stretch %>% 
model(tslm = TSLM(Close ~ Volume + Low + qt + dow))



f <- new_data(google_2015_stretch, 1) %>% 
mutate(Volume = 1447601, 
       Low = 700, 
       qt = quarter(Date),
       dow =  as.factor(weekdays(Date)))

fc <- forecast(fit_cv, new_data = f) 

fc %>% accuracy(
google_2015, 
list(rmse = RMSE, mae = MAE, mape = MAPE, mase = MASE, crps = CRPS, winkler = winkler_score)
) %>% 
arrange(rmse)

Please, if someone could help me, will be appreciated

0

There are 0 answers