forecast.marssMLE | R Documentation |
MARSS()
outputs marssMLE
objects. forecast(object)
, where object is marssMLE
object, will return the forecasts of \mathbf{y}_t
or \mathbf{x}_t
for h
steps past the end of the model data. forecast(object)
returns a marssPredict
object which can be passed to plot.marssPredict
for automatic plotting of the forecast. forecast.marssMLE()
is used by predict.marssMLE()
to generate forecasts.
This is a method for the generic forecast
function in the generics package. It is written to mimic the behavior and look of the forecast package.
## S3 method for class 'marssMLE'
forecast(object, h = 10, level = c(0.8, 0.95),
type = c("ytT","xtT", "ytt", "ytt1", "xtt", "xtt1"),
newdata = list(y = NULL, c = NULL, d = NULL),
interval = c("prediction", "confidence", "none"),
fun.kf = c("MARSSkfas", "MARSSkfss"), ...)
object |
A |
h |
Number of steps ahead to forecast. |
level |
Level for the intervals if |
type |
The default for observations would be |
newdata |
An optional list with matrices for new covariates |
interval |
If |
fun.kf |
Only if you want to change the default Kalman filter. Can be ignored. |
... |
Other arguments. Not used. |
The type="ytT"
forecast for T+i
is
\mathbf{Z}\mathbf{x}_{T+i}^T + \mathbf{a} + \mathbf{D}\mathbf{d}_{T+i}
where \mathbf{Z}
, \mathbf{a}
and \mathbf{D}
are estimated from the data from t=1
to T
. If the model includes \mathbf{d}_t
then newdata
with d
must be passed in. Either confidence or prediction intervals can be shown. Prediction intervals would be the norm for forecasts and show the intervals for new data which based on the conditional variance of \mathbf{Z}\mathbf{X}_{T+i} + \mathbf{V}_{T+i}
. Confidence intervals would show the variance of the mean of the new data (such as if you ran a simulation multiple times and recorded only the mean observation time series). It is based on the conditional variance of \mathbf{Z}\mathbf{X}_{T+i}
. The intervals shown are computed with fitted()
.
The type="xtT"
forecast for T+i
is
\mathbf{B}\mathbf{x}_{T+i-1}^T + \mathbf{u} + \mathbf{C}\mathbf{c}_{T+i}
where \mathbf{B}
and \mathbf{u}
and \mathbf{C}
are estimated from the data from t=1
to T
(i.e. the estimates in the marssMLE object). If the model includes \mathbf{c}_t
then newdata
with c
must be passed in. The only intervals are confidence intervals which based on the conditional variance of \mathbf{B}\mathbf{X}_{T+i-1} + \mathbf{W}_{T+i}
. If you pass in data for your forecast time steps, then the forecast will be computed conditioned on the original data plus the data in the forecast period. The intervals shown are computed with the Kalman smoother (or filter if type="xtt"
or type="xtt1"
specified) via tsSmooth()
.
If the model has time-varying parameters, the parameter estimates at time T
will be used for the whole forecast. If new data c
or d
are passed in, it must have h
time steps.
Note: y
in newdata
. Data along with covariates can be passed into newdata
. In this case, the data in newdata
(T+1
to T+h
) are conditioned on for the expected value of \mathbf{X}_t
but parameters used are only estimated using the data in the marssMLE object (t=1
to T
). If you include data in newdata
, you need to decide how to condition on that
new data for the forecast. type="ytT"
would mean that the t=T+i
forecast is conditioned on all the data, t=1
to T+h
, type="ytt"
would mean that the
t=T+i
forecast is conditioned on the data, t=1
to T+i
, and type="ytt1"
would mean that the t=T+i
forecast is conditioned on the data, t=1
to T+i-1
. Because MARSS models can be used in all sorts of systems, the \mathbf{y}
part of the MARSS model might not be "data" in the traditional sense. In some cases, one of the \mathbf{y}
(in a multivariate model) might be a known deterministic process or it might be a simulated future \mathbf{y}
that you want to include. In this case the
\mathbf{y}
rows that are being forecasted are NAs and the \mathbf{y}
rows that are known are passed in with newdata
.
A list with the following components:
method |
The method used for fitting, e.g. "kem". |
model |
The |
newdata |
The |
level |
The confidence |
pred |
A data frame the forecasts along with the intervals. |
type |
The |
t |
The time steps used to fit the model (used for plotting). |
h |
The number of forecast time steps (used for plotting). |
Eli Holmes, NOAA, Seattle, USA.
plot.marssPredict()
, predict.marssMLE()
# More examples are in ?predict.marssMLE
dat <- t(harborSealWA)
dat <- dat[2:4,] #remove the year row
fit <- MARSS(dat, model=list(R="diagonal and equal"))
# 2 steps ahead forecast
fr <- forecast(fit, type="ytT", h=2)
plot(fr)
# forecast and only show last 10 steps of original data
fr <- forecast(fit, h=10)
plot(fr, include=10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.