Learn R Programming

dlmodeler (version 1.4-2)

dlmodeler.build.structural: Build a structural time series model

Description

Builds a DLM for a structural time series, consisting of a polynomial term (level, trend, ...), a "dummy seasonal" pattern, a trigonometric cycle term, and an observation disturbance.

Usage

dlmodeler.structural(pol.order = NULL, dseas.order = NULL, tseas.period = NULL, tseas.order = NULL, sigmaH = NA, pol.sigmaQ = 0, dseas.sigmaQ = 0, tseas.sigmaQ = 0, name = "structural")
dlmodeler.build.structural(pol.order = NULL, dseas.order = NULL, tseas.period = NULL, tseas.order = NULL, sigmaH = NA, pol.sigmaQ = 0, dseas.sigmaQ = 0, tseas.sigmaQ = 0, name = "structural")

Arguments

pol.order
order of the polynomial (0=constant, 1=linear, 2=cubic...), or NULL to ignore polynomial component.
dseas.order
period of the dummy seasonal pattern, or NULL to ignore dummy seasonal component.
tseas.period
period of the trigonometric seasonal pattern, or NULL to ignore trigonometric component.
tseas.order
number of harmonics in the trigonometric seasonal pattern, or NULL. Optional when tseas.period is an integer (a default value is used), mandatory otherwise.
sigmaH
std dev of the observation disturbance (if unknown, set to NA and use dlmodeler.fit to estimate it). Default = NA.
pol.sigmaQ
std dev of the polynomial state disturbances (if unknown, set to NA and use dlmodeler.fit to estimate it). Default = 0.
dseas.sigmaQ
std dev of the dummy seasonal state disturbances (if unknown, set to NA and use dlmodeler.fit to estimate it). Default = 0.
tseas.sigmaQ
std dev of the trigonometric seasonal state disturbances (if unknown, set to NA and use dlmodeler.fit to estimate it). Default = 0.
name
an optional name to be given to the resulting DLM.

Value

An object of class dlmodeler representing the structural model. This object can have the following components:
level
component representing the level (when pol.order = 0)
level+trend
component representing the level+trend (when pol.order = 1)
polynomial
component representing the level, trend, ... (when pol.order > 1)
seasonal
component representing the dummy seasonal pattern
trigonometric
component representing the trigonometric seasonal pattern

Details

The initial value P0inf is parametered to use exact diffuse initialisation (if supported by the back-end).

References

Durbin, and Koopman, Time Series Analysis by State Space Methods, Oxford University Press (2001), pages 38-45.

See Also

dlmodeler, dlmodeler.build, dlmodeler.build.polynomial, dlmodeler.build.dseasonal, dlmodeler.build.tseasonal, dlmodeler.build.arima, dlmodeler.build.regression

Examples

Run this code
## Not run: 
# require(dlmodeler)
# 
# # generate some quarterly data
# n <- 80
# level <- 12
# sigma <- .75
# season <- c(5,6,8,2)
# y <- level + rep(season,n/4) + rnorm(n, mean=0, sd=sigma)
# 
# # deterministic level + quarterly seasonal
# mod <- dlmodeler.build.structural(pol.order=0, dseas.order=4,
#                                   sigmaH=sigma)
# f <- dlmodeler.filter(y, mod)
# 
# # show the one step ahead forecasts
# par(mfrow=c(2,1))
# plot(y,type='l')
# lines(f$f[1,],col='light blue')
# 
# # show the filtered level and seasonal components
# c <- dlmodeler.extract(f,mod,type="state")
# lines(c$level[1,],col='blue')
# plot(c$seasonal[1,],type='l',col='dark green')
# ## End(Not run)

Run the code above in your browser using DataLab