add.seasonal function

Seasonal State Component

Seasonal State Component

Add a seasonal model to a state specification.

The seasonal model can be thought of as a regression on nseasons dummy variables with coefficients constrained to sum to 1 (in expectation). If there are S seasons then the state vector gammagamma is of dimension S-1. The first element of the state vector obeys [REMOVE_ME]γt+1,1=i=2Sγt,i+ϵtϵtN(0,σ) \gamma_{t+1, 1} = -\sum_{i = 2}^S \gamma_{t, i} + \epsilon_t\qquad \epsilon_t \sim \mathcal{N}(0, \sigma)%gamma[t+1, 1] = -1 * sum(gamma[t, -1]) + rnorm(1, 0, sigma) [REMOVE_ME_2] 1.1

Description

Add a seasonal model to a state specification.

The seasonal model can be thought of as a regression on nseasons dummy variables with coefficients constrained to sum to 1 (in expectation). If there are S seasons then the state vector gammagamma is of dimension S-1. The first element of the state vector obeys

γt+1,1=i=2Sγt,i+ϵtϵtN(0,σ) \gamma_{t+1, 1} = -\sum_{i = 2}^S \gamma_{t, i} + \epsilon_t\qquad \epsilon_t \sim \mathcal{N}(0, \sigma)%gamma[t+1, 1] = -1 * sum(gamma[t, -1]) + rnorm(1, 0, sigma)
AddSeasonal( state.specification, y, nseasons, season.duration = 1, sigma.prior, initial.state.prior, sdy)

Arguments

  • state.specification: A list of state components that you wish to add to. If omitted, an empty list will be assumed.

  • y: The time series to be modeled, as a numeric vector.

  • nseasons: The number of seasons to be modeled.

  • season.duration: The number of time periods in each season.

  • sigma.prior: An object created by SdPrior

    describing the prior distribution for the standard deviation of the random walk increments.

  • initial.state.prior: An object created using NormalPrior, describing the prior distribution of the the initial state vector (at time 1).

  • sdy: The standard deviation of the series to be modeled. This will be ignored if y is provided, or if all the required prior distributions are supplied directly.

Returns

Returns a list with the elements necessary to specify a seasonal state model.

References

Harvey (1990), "Forecasting, structural time series, and the Kalman filter", Cambridge University Press.

Durbin and Koopman (2001), "Time series analysis by state space methods", Oxford University Press.

Author(s)

Steven L. Scott steve.the.bayesian@gmail.com

See Also

bsts. SdPrior

NormalPrior

Examples

data(AirPassengers) y <- log(AirPassengers) ss <- AddLocalLinearTrend(list(), y) ss <- AddSeasonal(ss, y, nseasons = 12) model <- bsts(y, state.specification = ss, niter = 500) pred <- predict(model, horizon = 12, burn = 100) plot(pred)
  • Maintainer: Steven L. Scott
  • License: LGPL-2.1 | MIT + file LICENSE
  • Last published: 2024-01-17

Useful links