tidyverts / fasster

Forecasting with Additive Switching of Seasonality, Trend and Exogenous Regressors
https://fasster.tidyverts.org/
150 stars 15 forks source link

Error running vignette example with poly() #29

Closed leungi closed 6 years ago

leungi commented 6 years ago

As per subject; taking out poly() term avoids the error.

library(fasster)
library(tsibble)
library(lubridate)

daytype <- function(date){
  factor(ifelse(wday(date) %in% 2:6, "Weekday", "Weekend"), levels = c("Weekday", "Weekend"))
}

SthCross_Ex <- pedestrian %>% 
  filter(Sensor == "Southern Cross Station") %>% 
  mutate(DayType = daytype(Date)) %>% 
  as_tsibble()

SthCross_fasster_fit <- SthCross_Ex %>%
  fasster(Count ~ DayType %S% (poly(1) + trig(24)))
#> Error in dlmSmooth.dlmFiltered(filtered): error code 1 from Lapack routine dgesdd

SthCross_fasster_fit <- SthCross_Ex %>%
  fasster(Count ~ DayType %S% (poly(1)))

Created on 2018-07-29 by the reprex package (v0.2.0).

mitchelloharawild commented 6 years ago

Vignette is still in progress, but I appreciate the suggestion.

I suspect you intend to say that removing trig(24) removes the error, however doing this will result in a terrible model. The optimisation technique needs improvement, however for now I think a slight change such as trig(24,11) might work.

This is something I'll need to play around with first.

leungi commented 6 years ago

Thanks for the prompt response @mitchoharawild, and the exciting package!

Indeed, I meant to say 'trig()'.

Curious, what analysis do you do to determine the 'q' in 'trig()' generally? Tuning via "grid search"?

mitchelloharawild commented 6 years ago

You certainly can tune it using grid search or similar algorithms.

The practical functionality of q is to limit the complexity of the model, which will improve the speed of the estimation. As mentioned in the vignette, if the seasonal pattern varies quickly (such as the pedestrian daily pattern), a large number of harmonics (q) is required. However, if the seasonal pattern is changing slowly (for example, annual seasonality in electricity demand), it is reasonable to have a very small number of harmonics. For example, with tsibbledata::elecdemand, the annual seasonality can be probably modelled with trig(17532, 10), as the annual pattern changes slowly and smoothly.

The additional benefit of reducing model complexity is that it increases the likelihood that Lapack will work.