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

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/tsglm.sim.R

Description

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

Usage

1
2
3
4
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 β[0].

past_obs

numeric non-negative vector containing the coefficients β[1], …, β[p] for regression on previous observations (see Details).

past_mean

numeric non-negative vector containing the coefficients α[1], …, α[q] for regression on previous conditional means (see Details).

xreg

numeric non-negative vector specifying the size ν[1], …, ν[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.

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.

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 κ[t] for all t=1, …, n.

xreg.effects

an object of class "ts" with the cumulated effect of the covariates η[1] X[t,1] + … + η[r] X[t,r] for all t=1, …, n.

Author(s)

Tobias Liboschik and Philipp Probst

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

1
2
3
4
5
6
#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))

Example output

$ts
Time Series:
Start = 1 
End = 200 
Frequency = 1 
  [1]  1  0  1  9  1  2  3  7  2  3  2 12  0  1  3 12  0  0  3  4  1  7  1  7  0
 [26]  6  0  0 14 21  7 14  3  7  1  0  0  6  4  1  3  0  0  0  4  0  1  0  2  4
 [51] 21 14 19 16  2  1  2  0 28 27 12  0  0  1  0  0  2 14  3  2  6 12  1  2 11
 [76] 24  5  1 18 10 11 20 41  4  6 13  5 21  6  1  1 21  1  4  0  1 19  5 18  2
[101] 16 29 36  8  3 18  7  7 11  9 10 12 12 35 33  2 19 25 17 54 18  4 48 47  0
[126]  8  2  3  1  6 18  0 32 41 30  9 45 33 25 14  2 18  4 26  0  3 13  4  3  2
[151]  0  7 37 17  5  6 69 38 13  3 12 12 18  3  9 21 20  7 33  7 16 15 65  1 12
[176] 35  7  7 13  2  0 15 16 15  7  0  1  2  5  5  6 29 44  6  7 15  0 10  8  0

$linear.predictors
Time Series:
Start = 1 
End = 200 
Frequency = 1 
  [1]  3.542809  3.405812  3.090168  3.271183  5.687642  3.982563  3.982302
  [8]  4.050741  5.250729  3.959163  4.018951  3.972554  6.792767  3.756784
 [15]  3.456431  4.116359  6.819188  3.765733  3.150402  4.209357  4.417550
 [22]  3.529153  5.217467  4.025412  5.281656  3.371371  4.895210  3.420797
 [29]  3.037075  7.329162 10.168374  6.661840  7.869505  4.963422  5.434764
 [36]  3.690660  3.471048  3.711047  5.208393  5.028629  3.802068  4.203890
 [43]  3.209844  2.989074  2.968919  4.314623  3.365788  3.353364  3.091062
 [50]  6.539197  7.806747 13.158241 12.263111 13.489201 12.833177  8.475742
 [57]  7.649068  7.910488  7.897922 16.205895 17.690099 13.421337  8.531842
 [64]  7.471275  7.585304  7.306853  8.081960  8.985402 12.339214  9.221027
 [71]  8.191333  9.196797 11.170045  8.342205  8.166981 11.167318 15.355566
 [78] 10.390247  8.297729 13.176550 11.469531 11.410604 14.398853 21.715327
 [85] 11.582090  9.946191 12.206893 10.088332 14.458727 11.131631  9.697859
 [92]  8.397781 13.974175  9.315524  9.071938  8.260260  8.065215 13.282829
 [99]  9.996344 13.796686  9.290890 12.565372 17.039100 20.014342 12.731151
[106]  9.445865 13.668842 10.762857 10.509109 12.105732 12.122581 11.697631
[113] 11.884113 12.343707 19.045027 19.759916 10.762556 14.064769 16.482717
[120] 14.584955 25.351362 17.374775 11.650947 22.806445 25.067766 11.661825
[127] 11.190860 10.373308  9.712139  8.407522 10.762149 15.059206  9.178024
[134] 17.554691 21.848269 19.340868 12.408926 22.058000 20.817521 17.581307
[141] 14.471730 10.679173 14.469921 10.334877 17.072775 10.496307  9.757392
[148] 12.298651  9.727648 19.292522 18.491992 16.805676 16.630766 24.497892
[155] 19.506244 13.995453 13.625495 31.952020 25.813149 16.799448 12.568672
[162] 13.751554 13.299612 14.862277 12.419501 13.046690 15.814463 15.599904
[169] 11.739251 18.693104 12.417082 13.599153 13.583529 28.845376 12.666844
[176] 12.337517 19.860992 12.333249 10.942039 12.459140 10.986269  8.471861
[183] 12.434462 14.278062 13.592994 10.916048  8.431720  8.087048  8.066257
[190]  9.358027  9.800475 10.120245 16.816334 22.406983 12.090537 10.325082
[197] 12.501098  8.480490 10.708301 11.223436

$xreg.effects
Time Series:
Start = 1 
End = 200 
Frequency = 1 
  [1]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
  [8]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [15]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [22]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [29]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [36]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [43]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [50]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [57]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [64]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [71]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [78]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [85]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [92]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
 [99]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[106]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[113]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[120]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[127]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[134]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[141]  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000  3.000000
[148]  3.000000  3.000000 13.000000 11.000000  9.400000  8.120000  7.096000
[155]  6.276800  5.621440  5.097152  4.677722  4.342177  4.073742  3.858993
[162]  3.687195  3.549756  3.439805  3.351844  3.281475  3.225180  3.180144
[169]  3.144115  3.115292  3.092234  3.073787  3.059030  3.047224  3.037779
[176]  3.030223  3.024179  3.019343  3.015474  3.012379  3.009904  3.007923
[183]  3.006338  3.005071  3.004056  3.003245  3.002596  3.002077  3.001662
[190]  3.001329  3.001063  3.000851  3.000681  3.000544  3.000436  3.000348
[197]  3.000279  3.000223  3.000178  3.000143

tscount documentation built on Sept. 8, 2020, 9:08 a.m.