View source: R/predict.SSModel.R
predict.SSModel | R Documentation |
Function predict.SSModel
predicts the future observations of a state
space model of class SSModel
.
## 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,
...
)
object |
Object of class |
newdata |
A compatible |
n.ahead |
Number of steps ahead at which to predict. Only used if
|
interval |
Type of interval calculation. |
level |
Confidence level for intervals. |
type |
Scale of the prediction, |
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
|
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 |
expected |
Logical value defining the approximation of H_t in case of Gamma
and negative binomial distribution. Default is |
... |
Ignored. |
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(\alpha | 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|\theta^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.
A matrix or list of matrices containing the predictions, and optionally standard errors.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.