mixed.frequency {bsts} | R Documentation |
Models for mixed frequency time series
Description
Fit a structured time series to mixed frequncy data.
Usage
bsts.mixed(target.series,
predictors,
which.coarse.interval,
membership.fraction,
contains.end,
state.specification,
regression.prior,
niter,
ping = niter / 10,
seed = NULL,
truth = NULL,
...)
Arguments
target.series |
A vector object of class |
predictors |
A matrix of class |
which.coarse.interval |
A numeric vector of length
|
membership.fraction |
A numeric vector of length
|
contains.end |
A logical vector of length |
state.specification |
A state specification like that required
by |
regression.prior |
A prior distribution created by
|
niter |
The desired number of MCMC iterations. |
ping |
An integer indicating the frequency with which progress
reports get printed. E.g. setting |
seed |
An integer to use as the random seed for the underlying
C++ code. If |
truth |
For debugging purposes only. A list containing one or more of the following elements. If any are present then corresponding values will be held fixed in the MCMC algorithm.
|
... |
Extra arguments passed to SpikeSlabPrior |
Value
An object of class bsts.mixed
, which is a list with the
following elements. Many of these are arrays, in which case the first
index of the array corresponds to the MCMC iteration number.
coefficients |
A matrix containing the MCMC draws of the regression coefficients. Rows correspond to MCMC draws, and columns correspond to variables. |
sigma.obs |
The standard deviation of the weekly latent observations. |
state.contributions |
A three-dimensional array containing the MCMC draws of each state model's contributions to the state of the weekly model. The three dimensions are MCMC iteration, state model, and week number. |
weekly |
A matrix of MCMC draws of the weekly latent observations. Rows are MCMC iterations, and columns are weekly time points. |
cumulator |
A matrix of MCMC draws of the cumulator variable. |
The returned object also contains MCMC draws for the parameters of the
state models supplied as part of state.specification
, relevant
information passed to the function call, and other supplemental
information.
Author(s)
Steven L. Scott steve.the.bayesian@gmail.com
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
,
AddLocalLevel
,
AddLocalLinearTrend
,
AddSemilocalLinearTrend
,
SpikeSlabPrior
,
SdPrior
.
Examples
## Not run:
data <- SimulateFakeMixedFrequencyData(nweeks = 104, xdim = 20)
## Setting an upper limit on the standard deviations can help keep the
## MCMC from flying off to infinity.
sd.limit <- sd(data$coarse.target)
state.specification <-
AddLocalLinearTrend(list(),
data$coarse.target,
level.sigma.prior = SdPrior(1.0, 5, upper.limit = sd.limit),
slope.sigma.prior = SdPrior(.5, 5, upper.limit = sd.limit))
weeks <- index(data$predictor)
months <- index(data$coarse.target)
which.month <- MatchWeekToMonth(weeks, months[1])
membership.fraction <- GetFractionOfDaysInInitialMonth(weeks)
contains.end <- WeekEndsMonth(weeks)
model <- bsts.mixed(target.series = data$coarse.target,
predictors = data$predictors,
membership.fraction = membership.fraction,
contains.end = contains.end,
which.coarse = which.month,
state.specification = state.specification,
niter = 500,
expected.r2 = .999,
prior.df = 1)
plot(model, "state")
plot(model, "components")
## End(Not run)