1
$\begingroup$

Here's the background. I have a time series representing daily sales. And I had built some models, like, ARIMA (arima), STL Decomposition (stl), Holt-winter (hw), and exponential smoothing state space model (result from the ets reduced to a hw model, because the returned model showed additive error/trend/seasonality), etc.

Anyway, the data is non-stationary, representing trend and weekly seasonality, which can also be proved with spectral analysis/periodogram. By using cross validation of 1-step to 15-step ahead forecast, I found stl decomposition gave me the best result in MAE.

Then, I started working on a dynamic linear model to see if I can build a better one for forecasting. The model is also written in R, with dlm, which is local linear + seasonal + ARMA model, and the code as below

build <- function(parm) {
    level0 <- 20
    slope0 <- 1
    # Level + Trend
    trend <- dlmModPoly(order = 2, dV = parm[1], dW = exp(parm[2:3]),
           m0 = c(level0, slope0),
           C0 = 400*diag(2))
    # Seasonal Term
    # Fourier Form Seasonal Model
    season <- dlmModTrig(s = 7, q = 4, , dW = parm[4])
    # ARMA Term
    arma <- dlmModARMA(ar = ARtransPars(parm[5:6]), ma = parm[7:8], sigma2 = parm[9])
    return(trend + season + arma)
}
# MLE for parameter estimation
init <- c(1e-07, -3, -1, 40, 0.5, 0.4, 0.7, 0.3, 1)
fit_dlm <- dlmMLE(y, parm = init, build, hessian = TRUE)

dlmSales <- build(fit_dlm$par)
f1 <- dlmForecast(dlmSales, n = 16)

My first question is, in the math modeling, there should be only one observation error, indicating that, there also should be only one dV in the R model. So, I only used the dV argument in dlmModPoly, is this correct?

I know that MLE is not considered the best way for estimating unknown parameters. As I read the book Dynamic Linear Model with R, it also gives methods like Bayesian Inferences with discount factor (with/without time-variant dV) or Simulation-based Bayesian inference.

Here are my questions

  • How do I use dlmFilterDF if my model consist of three parts, which is mod <- dlmModPoly + dlmModTrig + dlmModARMA? Can I do this modFilt <- dlmFilterDF(y, mod, DF = 0.9) directly?
  • When applying dlmGibbsDIG, can I assign vectors to a.theta and b.theta? because the unknown parameters $\psi$ in my case is of length 10 (1 for dV, 2 for local linear dW, 6 for seasonality dW, 1 for ARMA dW).
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.