0

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

user290703
  • 11
  • 1
  • *"...I got an issue"* Which exactly? – JaSON Apr 20 '21 at 15:05
  • Actually I got two: f <- new_data(google_2015_stretch, 1) %>% mutate(Volume = 1447601, Low = 700, qt = quarter(Date), dow = as.factor(weekdays(Date))) Error: Problem with `mutate()` input `qt`. x do not know how to convert 'x' to class “POSIXlt” ℹ Input `qt` is `quarter(Date)`. fc <- forecast(fit_cv, new_data = f) Error: Problem with `mutate()` input `tslm`. x contrasts can be applied only to factors with 2 or more levels Unable to compute required variables from provided `new_data`. – user290703 Apr 20 '21 at 15:14

0 Answers0