5

Using the R package "bsts", I am attempting to forecast daily data from 3 years of history. The model looks good, and the forecast looks good, other than the fact that it fails to account for the Memorial Day effect.

I thought that using the NamedHolidays function in my state specifications would automatically detect the Memorial Day holiday and appropriately apply the Memorial Holiday effect in my forecast. It doesn't appear that is happening.

My question is twofold:

1) Do the forecasts from bsts automatically incorporate fixed holidays if I have specified them in the state specifications?

2) If the answer to the above is "no", then does anyone have an idea about how I can manually apply the effects by pulling them from the model? If the answer is "yes", then how do I do it? Or test if it has been done so I can determine if the Memorial Day miss in my forecast is due to other factors?

The code for developing the state specifications is below, as is a plot of actuals (black) versus forecast (red). I cannot share data because it is proprietary and I don't know how to create the Memorial Day effect in dummy data so that it has the same impact.

# build named holidays list and effects (days.before and days.after)
holidayNames <- list("MartinLutherKingDay" = c(3, 3),
                 "PresidentsDay" = c(3, 3), 
                 "MemorialDay" = c(3, 3), 
                 "LaborDay" = c(3, 3),
                 "Thanksgiving" = c(1, 4),
                 "ColumbusDay" = c(1, 2), 
                 "VeteransDay" = c(1, 2),
                 "NewYearsDay" = c(3, 3), 
                 "IndependenceDay" = c(3, 3), 
                 "Christmas" = c(3, 3))

# build holidays for model
holidaylist <- list()
for(h in names(holidayNames)){
    holidaylist[[h]] <- NamedHoliday(holiday.name = h, days.before = 
    holidayNames[[h]][1], days.after = holidayNames[[h]][2])
}

# build model state specs
ss <- list()

ss <- AddLocalLinearTrend(ss, traindat)
ss <- AddRegressionHoliday(ss, traindat, holiday.list = holidaylist)  
ss <- AddSeasonal(ss, traindat, nseasons = 7) 
ss <- AddSeasonal(ss, traindat,  nseasons = 52, season.duration = 7)
ss <- AddMonthlyAnnualCycle(ss, traindat)

# train model
mod <- bsts(traindat, state.specification = ss, niter = 5000) 

# forecast
pred <- predict(mod, horizon = 90, timestamps = index(testdat), quantiles = 
c(.025, .975))

# plot actual v. predicted

enter image description here

mmmm
  • 53
  • 5
  • 1
    [Please consider posting a reproducible example.](https://stackoverflow.com/q/5963269/452096) We probably won't be able to help you otherwise. – Stephan Kolassa Jul 11 '18 at 06:06

0 Answers0