Description Usage Arguments Details Value References See Also Examples
Evaluate the spectral generating function of of common structural models: local level model, local trend model and basic structural model.
1 |
x |
object of class |
gradient |
logical. If |
hessian |
logical. If |
deriv.transPars |
logical. If |
The stationary form of the local level model is (Δ is the differencing operator):
Δ y[t] = v[t] + Δ e[t]
and its spectral generating function at each frequency λ[j] = 2π j/T for j=0,...,T-1 is:
g(λ[j]) = σ^2_2 + 2(1 - cos λ[j]) σ^2_1
The stationary form of the local trend model for a time series of frequency S is:
Δ^2 y[t] = Δ v[t] + w[t-1] + Δ^2 e[t]
and its spectral generating function is:
g(λ[j]) = 2(1 - cos λ[j]) σ^2_2 + σ^2_3 + 4(1 - cos λ[j]) σ^2_1
The stationary form of the basic structural model for a time series of frequency p is:
Δ Δ^p y[t] = Δ^p v[t] + S(L) w[t-1] + Δ^2 s[t] + Δ Δ^p e[t]
and its spectral generating function is:
g(λ[j]) = g_v(λ[j]) σ^2_2 + g_w(λ[j]) σ^2_3 + g_s(λ[j]) σ^2_4 + g_e(λ[j]) σ^2_1
with
g_v(λ[j]) = 2(1 - cos(λ[j] p))
g_w(λ[j]) = (1 - cos(λ[j] p))/(1 - cos(λ[j]))
g_s(λ[j]) = 4 (1 - cos(λ[j]))^2
g_e(λ[j]) = 4 (1 - cos(λ[j])) (1 - cos(λ[j] p))
A list containing the following results:
sgf |
spectral generating function of the BSM model at each frequency λ[j] for j=0,…,T-1. |
gradient |
first order derivatives of the spectral generating function with respect of the parameters of the model. |
hessian |
second order derivatives of the spsectral generating function with respect of the parameters of the model. |
constants |
the terms g_v(λ[j]), g_w(λ[j]), g_s(λ[j]) and g_e(λ[j]) that do not depend on the variance parameters. |
Harvey, A. C. (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press.
set.sgfc
,
stsm-class
,
stsm.model
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # 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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.