stsm.class (version 1.3)

stsm.sgf: Spectral Generating Function of Common Structural Time Series Models

Description

Evaluate the spectral generating function of of common structural models: local level model, local trend model and basic structural model.

Usage

stsm.sgf(x, gradient = FALSE, hessian = FALSE, deriv.transPars = FALSE)

Arguments

x
object of class stsm.
gradient
logical. If TRUE, the gradient is returned.
hessian
logical. If TRUE, hessian the gradient is returned.
deriv.transPars
logical. If TRUE, the gradient and the Hessian are scaled by the gradient of the function that transforms the parameters. Ignored if x@transPars is null.

Value

  • A list containing the following results:
  • sgfspectral generating function of the BSM model at each frequency $\lambda[j]$ for $j=0,\dots,T-1$.
  • gradientfirst order derivatives of the spectral generating function with respect of the parameters of the model.
  • hessiansecond order derivatives of the spsectral generating function with respect of the parameters of the model.
  • constantsthe terms $g_v(\lambda[j])$, $g_w(\lambda[j])$, $g_s(\lambda[j])$ and $g_e(\lambda[j])$ that do not depend on the variance parameters.

Details

The stationary form of the local level model is ($\Delta$ is the differencing operator):

$$\Delta y[t] = v[t] + \Delta e[t]$$

and its spectral generating function at each frequency $\lambda[j] = 2\pi j/T$ for $j=0,...,T-1$ is:

$$g(\lambda[j]) = \sigma^2_2 + 2(1 - cos \lambda[j]) \sigma^2_1$$

The stationary form of the local trend model for a time series of frequency $S$ is:

$$\Delta^2 y[t] = \Delta v[t] + w[t-1] + \Delta^2 e[t]$$

and its spectral generating function is:

$$g(\lambda[j]) = 2(1 - cos \lambda[j]) \sigma^2_2 + \sigma^2_3 + 4(1 - cos \lambda[j]) \sigma^2_1$$

The stationary form of the basic structural model for a time series of frequency $p$ is:

$$\Delta \Delta^p y[t] = \Delta^p v[t] + S(L) w[t-1] + \Delta^2 s[t] + \Delta \Delta^p e[t]$$

and its spectral generating function is:

$$g(\lambda[j]) = g_v(\lambda[j]) \sigma^2_2 + g_w(\lambda[j]) \sigma^2_3 + g_s(\lambda[j]) \sigma^2_4 + g_e(\lambda[j]) \sigma^2_1$$

with

$$g_v(\lambda[j]) = 2(1 - cos(\lambda[j] p))$$ $$g_w(\lambda[j]) = (1 - cos(\lambda[j] p))/(1 - cos(\lambda[j]))$$ $$g_s(\lambda[j]) = 4 (1 - cos(\lambda[j]))^2$$ $$g_e(\lambda[j]) = 4 (1 - cos(\lambda[j])) (1 - cos(\lambda[j] p))$$

References

Harvey, A. C. (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press.

See Also

set.sgfc, stsm-class, stsm.model.

Examples

Run this code
# spectral generating function of the local level plus seasonal model
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = 2, "var2" = 15), nopars = c("var3" = 30))
res <- stsm.sgf(m)
res$sgf
plot(res$sgf)
res$constants
# the element 'constants' contains the constant variables
# related to each component regardless of whether the 
# variances related to them are in the slot 'pars' or 'nopars'
names(get.pars(m))
colnames(res$constants)

# compare analytical and numerical derivatives
# identical values
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = 2, "var2" = 15, "var3" = 30))
res <- stsm.sgf(m, gradient = TRUE)

fcn <- function(x, model = m) {
  m <- set.pars(model, x)
  res <- stsm.sgf(m)
  sum(res$sgf)
}

a1 <- numDeriv::grad(func = fcn, x = get.pars(m))
a2 <- colSums(res$grad)
all.equal(a1, a2, check.attributes = FALSE)

# analytical derivatives are evaluated faster than numerically
system.time(a1 <- numDeriv::grad(func = fcn, x = get.pars(m)))
system.time(a2 <- colSums(stsm.sgf(m, gradient = TRUE)$grad))

Run the code above in your browser using DataLab