Learn R Programming

bsts (version 0.7.1)

add.trig: Trigonometric seasonal state component

Description

Add a trigonometric seasonal model to a state specification.

The trig component adds a collection of sine and cosine terms with randomly varying coefficients to the state model. The coefficients are the states, while the sine and cosine values are part of the "observation matrix".

This state component adds the sum of its terms to the observation equation.

$$y_t = \sum_j \beta_{jt} sin(f_j t) + \gamma_{jt} cos(f_j t)$$

The evolution equation is that each of the sinusoid coefficients follows a random walk with standard deviation sigma[j].

$$\beta_{jt} = \beta_{jt-1} + N(0, sigma_{sj}^2)) \gamma_{jt} = \gamma_{j-1} + N(0, sigma_{cj}^2) $$

Usage

AddTrig(
     state.specification = NULL,
     y,
     period,
     frequencies,
     sigma.prior = NULL,
     initial.state.prior = NULL,
     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.

period

A positive scalar giving the number of time steps required for the longest cycle to repeat.

frequencies

A vector of positive real numbers giving the number of times each cyclic component repeats in a period. One sine and one cosine term will be added for each frequency.

sigma.prior

An object created by SdPrior describing the prior distribution for the standard deviation of coefficients of the sinusoid terms.

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.

Value

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.

See Also

bsts. SdPrior MvnPrior

Examples

Run this code
# NOT RUN {
  data(AirPassengers)
  y <- log(AirPassengers)
  ss <- AddLocalLinearTrend(list(), y)
  ss <- AddTrig(ss, y, period = 12, frequencies = 1)
  model <- bsts(y, state.specification = ss, niter = 100)
  plot(model)
# }

Run the code above in your browser using DataLab