tscount (version 1.4.3)

tsglm.sim: Simulate a Time Series Following a Generalised Linear Model

Description

Generates a simulated time series from a GLM-type model for time series of counts (see tsglm for details).

Usage

tsglm.sim(n, param = list(intercept = 1, past_obs = NULL, past_mean = NULL,
            xreg = NULL), model = list(past_obs = NULL, past_mean = NULL,
            external = FALSE), xreg = NULL, link = c("identity", "log"),
            distr = c("poisson", "nbinom"), distrcoefs, fit, n_start = 50)

Arguments

n

integer value giving the number of observations to be simulated.

param

a named list giving the parameters for the linear predictor of the model, which has the following elements:

intercept

numeric positive value for the intercept \(\beta_0\).

past_obs

numeric non-negative vector containing the coefficients \(\beta_1,\ldots, \beta_p\) for regression on previous observations (see Details).

past_mean

numeric non-negative vector containing the coefficients \(\alpha_1,\ldots, \alpha_q\) for regression on previous conditional means (see Details).

xreg

numeric non-negative vector specifying the size \(\nu_1,\ldots, \nu_r\) of each intervention

model

a named list specifying the model for the linear predictor, which has the elements past_obs, past_mean and external (see function tsglm for details). This model specification must be in accordance to the parameters given in argument param.

xreg

matrix with covariates in the columns (see tsglm for details). Its number of rows must be equal to the number of observations which should be simulated.

link

character giving the link function. Default is "identity", simulating from a so-called INGARCH model. Another possible choice is "log", simulating from a log-linear model.

distr

character giving the conditional distribution. Default is "poisson", i.e. a Poisson distribution.

distrcoefs

numeric vector of additional coefficients specifying the conditional distribution. For distr="poisson" no additional parameters need to be provided. For distr="nbinom" the additional parameter size needs to be specified (e.g. by distrcoefs=2), see tsglm for details.

fit

an object of class "tsglm". Usually the result of a call to tsglm. If argument fit is not missing, the specification of the linear predictor, the link function and the estimated parameters from this argument are used instead of those in arguments model, link and param. The length of the simulated time series is only taken from argument fit, if no argument n is provided. The same holds for arguments xreg, distr and distrcoefs, which are also prefered over the respective information provided in argument fit if both are provided.

n_start

number of observations used as a burn-in.

Value

A list with the following components:

ts

an object of class "ts" with the simulated time series.

linear.predictors

an object of class "ts" with the simulated linear predictors \(\kappa_t\) for all \(t=1, \ldots, n\).

xreg.effects

an object of class "ts" with the cumulated effect of the covariates \(\eta_1 X_{t,1} + \ldots + \eta_r X_{t,r}\) for all \(t=1, \ldots, n\).

Details

The definition of the model used here is like in function tsglm.

Note that during the burn-in period covariates are set to zero.

If a previous model fit is given in argument fit and the length of the burn-in period n_start is set to zero, then the a continuation of the original time series is simulated.

References

Liboschik, T., Fokianos, K. and Fried, R. (2017) tscount: An R package for analysis of count time series following generalized linear models. Journal of Statistical Software 82(5), 1--51, http://dx.doi.org/10.18637/jss.v082.i05.

See Also

tsglm for fitting a GLM for time series of counts.

Examples

Run this code
# NOT RUN {
#Simulate from an INGARCH model with two interventions:
interventions <- interv_covariate(n=200, tau=c(50, 150), delta=c(1, 0.8))
model <- list(past_obs=1, past_mean=c(1, 7), external=FALSE)
param <- list(intercept=2, past_obs=0.3, past_mean=c(0.2, 0.1), xreg=c(3, 10))
tsglm.sim(n=200, param=param, model=model, xreg=interventions, link="identity",
          distr="nbinom", distrcoefs=c(size=1))
# }

Run the code above in your browser using DataCamp Workspace