"predict"(object, n.ahead=1, newobs=NULL, newxreg=NULL, level=0.95, global=FALSE, type=c("quantiles", "shortest", "onesided"), method=c("conddistr", "bootstrap"), B=1000, estim=c("ignore", "bootstrap", "normapprox", "given"), B_estim=B, coefs_given, ...)
"tsglm"
. Usually the result of a call to tsglm
.
n.ahead
greater than 1). The $h$-step-ahead prediction for $h>1$ is computed as a 1-step-ahead prediction given all previous values, which can be observations of the original time series or new observations provided in this argument. Previous observations which are not available are replaced by their respective 1-step-ahead prediction.
newxreg
is omitted or contains less rows than the value of n.ahead
, the last known values of the covariates are used for prediction. This is usually not reasonable and it is strongly advised to explicitely make assumptions on future covariates and to specify the argument xreg
accordingly.
level=0
no prediction intervals are computed.
level
holds globally (global=TRUE
) or for each of the n.ahead
prediction intervals individually (global=FALSE
, the default). In the former case the individual coverage rate for a single prediction interval is Bonferroni adjusted to a level of 1-(1-level)/n.ahead
.
type="quantiles"
(the default), its limits are chosen to be the a
- and (1-a)
-quantiles of the respective (approximated) distribution, with a=(1-level)/2
. If type="shortest"
it is chosen such that it has minimal length. Note that these two types of construction principles frequently lead to the same result. If type="onesided"
a one-sided prediction interval is constructed where the lower boundary is always zero.
method="conddistr"
the prediction intervals are based on the conditional distribution given by the model with the unknown parameters being replaced by their respective estimations. This is only possible if only 1-step-ahead predictions are to be computed (possibly recursively using the new observations given in argument newobs
). If method="bootstrap"
the predictive distribution is approximated by a parametric bootstrap where B
trajectories of the process are simulated from the fitted model. This is currently only possible if no new observations are given in argument newobs
. By default the method "conddistr"
is prefered whenever it is appliccable.
method="bootstrap"
).
estim="ignore"
(the default), this additional uncertainty is ignored. The other two options (estim="bootstrap"
and estim="normapprox"
) are only possible if method="bootstrap"
. If these are selected the bootstrap samples are not generated from a model with the parameters of the original fit. Instead, each of the B
bootstrap samples is generated from a model with parameters which are itself randomly generated. This two-stage approach should take into account the additional estimation uncertainty.
If estim="bootstrap"
, the parameters are obtained from a fit to a parametric bootstrap replication of the original time series.
If estim="normapprox"
, the regression parameters are generated from a multivariate normal distribution which is based on the normal approximation of the original quasi maximum likelihood estimator and reflects the estimation uncertainty. In that case the additional distribution coefficients are not randomly generated such that their estimation uncertainty is ignored.
If estim="given"
, the parameters are resampled from a table of possible parameters which need to be given in argument coefs_given
.
estim="bootstrap"
and estim="normapprox"
. If B_estim
is smaller than B
, the parameters are resampled with replacement.
estim="given"
). If nrow(coefs_given)
is smaller than B
, the parameters are resampled with replacement.
"ts"
if the response used for fitting has this class."lower"
and "upper"
giving the lower and upper boundaries of prediction intervals for the future time points, each with an intended coverage rate as given in argument level
. Has class "ts"
if the response used for fitting has this class.level
holds globally or for each of the prediction intervals individually."quantiles"
and "shortest"
."conddistr"
and "bootstrap"
.NULL
if computation was done by method="conddistr"
."ignore"
, "bootstrap"
, "normapprox"
and "given"
.NULL
if no warning messages occured."ts"
if the response used for fitting has this class.n.ahead
observations following the fitted time series contained in argument object
. The 1-step-ahead prediction is the conditional expectation of the observation to be predicted given the past. The true parameters are replaced by their estimations given in argument object
. For a 2-step-ahead-prediction the true previous observation is used when given in argument newobs
, otherwise it is replaced by the 1-step-ahead prediction computed before. For a 3-step-prediction this holds for the previous two observations, which are replaced by their respective predictions if not available, and so on.Unless level=0
, the function also returns prediction intervals. Read the description of the arguments type
andmethod
for further details on the computation. Note that the prediction intervals do not reflect the additional uncertainty induced by the parameter estimation. However, for sufficiently long time series used for model fitting, it is expected that this uncertainty is negligible compared to the uncertainty of the predictive distribution. The argument estim
allows to account fot this additional estimation uncertainty if method="bootstrap"
, see the description of this argument.
If prediction intervals are computed the function additionally returns the median of the predictive distribution. If method="conddistr"
this is the analytical median of the conditional distribution, otherwise the empirical median of the simulated distribution.
tsglm
for fitting a GLM for time series of counts.
###Campylobacter infections in Canada (see help("campy"))
campyfit <- tsglm(ts=campy, model=list(past_obs=1, past_mean=c(7,13)))
predict(campyfit, n.ahead=1) #prediction interval using conditional distribution
predict(campyfit, n.ahead=5, global=TRUE) #prediction intervals using parametric bootstrap
Run the code above in your browser using DataLab