I am using Prophet for a multi-channel leads forecast. I've been able to make the prediction using the method described by @RLave in this post Prophet Forecasting using R for multiple items. I would like to add regressors to my forecast. Below is the example given by @RLave along with an example of how I have tried to add regressor and the results. How do I make add_regressor work with my leads list?
# also contains the purrr package
library(tidyverse)
set.seed(123)
tb1 <- tibble(
ds = seq(as.Date("2018-01-01"), as.Date("2018-12-31"), by = "day"),
y = sample(365)
regressor = rnorm(365, mean = 0, sd = 1)
)
tb2 <- tibble(
ds = seq(as.Date("2018-01-01"), as.Date("2018-12-31"), by = "day"),
y = sample(365)
regressor = rnorm(365, mean = 0, sd = 1)
)
# two separate time series
ts_list <- list(tb1, tb2)
Build and prediction:
library(prophet)
# prophet call
m_list <- map(ts_list, prophet)
# makes future obs
future_list <- map(m_list, make_future_dataframe, periods = 40)
# map2 because we have two inputs
forecast_list <- map2(m_list, future_list, predict)
Attempt to Add Regressor
m <- prophet()
m <- add_regressor(m, "regressor")
# prophet call
m_list2 <- map2(m, ts_list, fit.prophet )
Error: Mapped vectors must have consistent lengths:
.x
has length 31
.y
has length 14