predict.SSModel: State Space Model Predictions

Description Usage Arguments Details Value Examples

View source: R/predict.SSModel.R

Description

Function predict.SSModel predicts the future observations of a state space model of class SSModel.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## S3 method for class 'SSModel'
predict(
  object,
  newdata,
  n.ahead,
  interval = c("none", "confidence", "prediction"),
  level = 0.95,
  type = c("response", "link"),
  states = NULL,
  se.fit = FALSE,
  nsim = 0,
  prob = TRUE,
  maxiter = 50,
  filtered = FALSE,
  expected = FALSE,
  ...
)

Arguments

object

Object of class SSModel.

newdata

A compatible SSModel object to be added in the end of the old object for which the predictions are required. If omitted, predictions are either for the past data points, or if argument n.ahead is given, n.ahead time steps ahead.

n.ahead

Number of steps ahead at which to predict. Only used if newdata is omitted. Note that when using n.ahead, object cannot contain time varying system matrices.

interval

Type of interval calculation.

level

Confidence level for intervals.

type

Scale of the prediction, "response" or "link".

states

Which states are used in computing the predictions. Either a numeric vector containing the indices of the corresponding states, or a character vector defining the types of the corresponding states. Possible choices are "all", "level", "slope" (which does not make sense as the corresponding Z is zero.), "trend", "regression", "arima", "custom", "cycle" or "seasonal", where "trend" extracts all states relating to trend. These can be combined. Default is "all".

se.fit

If TRUE, standard errors of fitted values are computed. Default is FALSE.

nsim

Number of independent samples used in importance sampling. Used only for non-Gaussian models.

prob

if TRUE (default), the predictions in binomial case are probabilities instead of counts.

maxiter

The maximum number of iterations used in approximation Default is 50. Only used for non-Gaussian model.

filtered

If TRUE, compute predictions based on filtered (one-step-ahead) estimates. Default is FALSE i.e. predictions are based on all available observations given by user. For diffuse phase, interval bounds and standard errors of fitted values are set to -Inf/Inf (If the interest is in the first time points it might be useful to use non-exact diffuse initialization.).

expected

Logical value defining the approximation of H_t in case of Gamma and negative binomial distribution. Default is FALSE which matches the algorithm of Durbin & Koopman (1997), whereas TRUE uses the expected value of observations in the equations, leading to results which match with glm (where applicable). The latter case was the default behaviour of KFAS before version 1.3.8. Essentially this is the difference between observed and expected information in GLM context.

...

Ignored.

Details

For non-Gaussian models, the results depend whether importance sampling is used (nsim>0). without simulations, the confidence intervals are based on the Gaussian approximation of p(α | y). Confidence intervals in response scale are computed in linear predictor scale, and then transformed to response scale. The prediction intervals are not supported. With importance sampling, the confidence intervals are computed as the empirical quantiles from the weighted sample, whereas the prediction intervals contain additional step of simulating the response variables from the sampling distribution p(y|θ^i).

Predictions take account the uncertainty in state estimation (given the prior distribution for the initial states), but not the uncertainty of estimating the parameters in the system matrices (i.e. Z, Q etc.). Thus the obtained confidence/prediction intervals can underestimate the true uncertainty for short time series and/or complex models.

If no simulations are used, the standard errors in response scale are computed using the Delta method.

Value

A matrix or list of matrices containing the predictions, and optionally standard errors.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(1)
x <- runif(n=100,min=1,max=3)
y <- rpois(n=100,lambda=exp(x-1))
model <- SSModel(y~x,distribution="poisson")
xnew <- seq(0.5,3.5,by=0.1)
newdata <- SSModel(rep(NA,length(xnew))~xnew,distribution="poisson")
pred <- predict(model,newdata=newdata,interval="prediction",level=0.9,nsim=100)
plot(x=x,y=y,pch=19,ylim=c(0,25),xlim=c(0.5,3.5))
matlines(x=xnew,y=pred,col=c(2,2,2),lty=c(1,2,2),type="l")

model <- SSModel(Nile~SSMtrend(1,Q=1469),H=15099)
pred <- predict(model,n.ahead=10,interval="prediction",level=0.9)
pred

KFAS documentation built on June 7, 2021, 5:06 p.m.