predict.tsglm
Predicts Method for Time Series of Counts Following Generalised Linear Models
Predict future observations based on a fitted GLMtype model for time series of counts.
 Keywords
 prediction
Usage
"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, ...)
Arguments
 object

an object of class
"tsglm"
. Usually the result of a call totsglm
.  n.ahead
 positive integer value giving the number of steps ahead for which predictions should be made.
 newobs

integer vector of known future observations of the time series. This argument is only relevant if more than one observation ahead is to be predicted (
n.ahead
greater than 1). The $h$stepahead prediction for $h>1$ is computed as a 1stepahead 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 1stepahead prediction.  newxreg

matrix or vector containing new values for the covariates to be used for prediction. If
newxreg
is omitted or contains less rows than the value ofn.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 argumentxreg
accordingly.  level

numeric value determining the desired coverage rate of prediction intervals. If
level=0
no prediction intervals are computed.  global

logical value saying whether the coverage rate for $Y[n+1],...,Y[n+h]$ specified by argument
level
holds globally (global=TRUE
) or for each of then.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 of1(1level)/n.ahead
.  type

character value saying how the prediction interval shall be constructed. If
type="quantiles"
(the default), its limits are chosen to be thea
 and(1a)
quantiles of the respective (approximated) distribution, witha=(1level)/2
. Iftype="shortest"
it is chosen such that it has minimal length. Note that these two types of construction principles frequently lead to the same result. Iftype="onesided"
a onesided prediction interval is constructed where the lower boundary is always zero.  method

character value saying which method to be used for computing the prediction intervals. If
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 1stepahead predictions are to be computed (possibly recursively using the new observations given in argumentnewobs
). Ifmethod="bootstrap"
the predictive distribution is approximated by a parametric bootstrap whereB
trajectories of the process are simulated from the fitted model. This is currently only possible if no new observations are given in argumentnewobs
. By default the method"conddistr"
is prefered whenever it is appliccable.  B

positive integer value giving the number of samples of a parametric bootstrap to use for numerical determination of prediction intervals (only necessary if argument
method="bootstrap"
).  estim

character value saying how the prediction intervals shall account for the additional uncertainty induced by the parameter estimation. This is particularly important if the model was fitted on a short time series. If
estim="ignore"
(the default), this additional uncertainty is ignored. The other two options (estim="bootstrap"
andestim="normapprox"
) are only possible ifmethod="bootstrap"
. If these are selected the bootstrap samples are not generated from a model with the parameters of the original fit. Instead, each of theB
bootstrap samples is generated from a model with parameters which are itself randomly generated. This twostage approach should take into account the additional estimation uncertainty. Ifestim="bootstrap"
, the parameters are obtained from a fit to a parametric bootstrap replication of the original time series. Ifestim="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. Ifestim="given"
, the parameters are resampled from a table of possible parameters which need to be given in argumentcoefs_given
.  B_estim

positive integer value giving the number of parameters used for resampling to account for estimation uncertainty. Only necessary for
estim="bootstrap"
andestim="normapprox"
. IfB_estim
is smaller thanB
, the parameters are resampled with replacement.  coefs_given

table with parameters in the rows. Only necessary for
estim="given"
). Ifnrow(coefs_given)
is smaller thanB
, the parameters are resampled with replacement.  ...
 further arguments are currently ignored. Only for compatibility with generic function.
Details
Returns predictions for the n.ahead
observations following the fitted time series contained in argument object
. The 1stepahead 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 2stepaheadprediction the true previous observation is used when given in argument newobs
, otherwise it is replaced by the 1stepahead prediction computed before. For a 3stepprediction 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.
Value

A list with at least the following element:
 pred
 a numeric vector of the predictions. Has class
"ts"
if the response used for fitting has this class. If prediction intervals are calculated, the list has the additional element:  interval
 a matrix with the columns
"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 argumentlevel
. Has class"ts"
if the response used for fitting has this class.  level
 a numeric value determining the desired coverage rate of prediction intervals.
 global
 a logical value saying whether the coverage rate
level
holds globally or for each of the prediction intervals individually.  type
 a character value saying how the prediction intervals were computed. Possible values are
"quantiles"
and"shortest"
.  method
 a character value saying which method were used for computation of prediction intervals. Possible values are
"conddistr"
and"bootstrap"
.  B
 an integer value giving the number of bootstrap samples which were used for computing prediction intervals. Is
NULL
if computation was done bymethod="conddistr"
.  estim
 a character value saying how the prediction intervals account for estimation uncertainty of the model parameters. Possible values are
"ignore"
,"bootstrap"
,"normapprox"
and"given"
.  B_estim
 an integer value giving the number of parameter values used for resampling to account for estimation uncertainty. This value is zero if the estimation uncertainty is ignored.
 warning_messages
 a character vector containing warning messages. This should be
NULL
if no warning messages occured.  median
 a vector giving the median of the predictive distribution for each of the future time points. Has class
"ts"
if the response used for fitting has this class.
See Also
tsglm
for fitting a GLM for time series of counts.
Examples
###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