Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dlmForecast

Prediction and simulation of future observations


Description

The function evaluates the expected value and variance of future observations and system states. It can also generate a sample from the distribution of future observations and system states.

Usage

dlmForecast(mod, nAhead = 1, method = c("plain", "svd"), sampleNew = FALSE)

Arguments

mod

an object of class "dlm", or a list with components m0, C0, FF, V, GG, and W, defining the model and the parameters of the prior distribution. mod can also be an object of class "dlmFiltered", such as the output from dlmFilter.

nAhead

number of steps ahead for which a forecast is requested.

method

method="svd" uses singular value decomposition for the calculations. Currently, only method="plain" is implemented.

sampleNew

if sampleNew=n for an integer n, them a sample of size n from the forecast distribution of states and observables will be returned.

Value

A list with components

a matrix of expected values of future states
R list of variances of future states
f matrix of expected values of future observations
Q list of variances of future observations
newStates list of matrices containing the simulated future values
of the states. Each component of the list corresponds
to one simulation.
newObs same as newStates, but for the observations.

The last two components are not present if sampleNew=FALSE.

Note

The function is currently entirely written in R and is not particularly fast. Currently, only constant models are allowed.

Author(s)

Giovanni Petris GPetris@uark.edu

Examples

## Comparing theoretical prediction intervals with sample quantiles
set.seed(353)
n <- 20; m <- 1; p <- 5
mod <- dlmModPoly() + dlmModSeas(4, dV=0)
W(mod) <- rwishart(2*p,p) * 1e-1
m0(mod) <- rnorm(p, sd=5)
C0(mod) <- diag(p) * 1e-1
new <- 100
fore <- dlmForecast(mod, nAhead=n, sampleNew=new)
ciTheory <- (outer(sapply(fore$Q, FUN=function(x) sqrt(diag(x))), qnorm(c(0.1,0.9))) +
             as.vector(t(fore$f)))
ciSample <- t(apply(array(unlist(fore$newObs), dim=c(n,m,new))[,1,], 1,
                    FUN=function(x) quantile(x, c(0.1,0.9))))
plot.ts(cbind(ciTheory,fore$f[,1]),plot.type="s", col=c("red","red","green"),ylab="y")
for (j in 1:2) lines(ciSample[,j], col="blue")
legend(2,-40,legend=c("forecast mean", "theoretical bounds", "Monte Carlo bounds"),
       col=c("green","red","blue"), lty=1, bty="n")

dlm

Bayesian and Likelihood Analysis of Dynamic Linear Models

v1.1-5
GPL (>= 2)
Authors
Giovanni Petris [aut, cre], Wally Gilks [ctb] (Author of original C code for ARMS)
Initial release
2018-05-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.