simulate.egf_model {epigrowthfit}R Documentation

Simulating Incidence Time Series

Description

Simulates equally spaced incidence time series according to a specified nonlinear model. Top level nonlinear model parameters vary between time series according to a fixed intercept model ~ts or random intercept model ~(1 | ts).

Usage

## S3 method for class 'egf_model'
simulate(object, nsim = 1, seed = NULL,
         mu, Sigma = NULL, tol = 1e-06, cstart = 0, tend = 100, ...)

Arguments

object

an egf_model object specifying a top level nonlinear model to be simulated.

nsim

a positive integer indicating a number of time series.

seed

an integer used to set the RNG state before simulation or, otherwise, NULL; see simulate.

mu

a numeric vector listing means across time series of top level nonlinear model parameters (link scale). It is assumed that elements are ordered as egf_top(object).

Sigma

a real, symmetric positive definite matrix to be used as the covariance matrix corresponding to mu. The default is equivalent to a zero matrix and is handled specially.

tol

a non-negative number indicating a tolerance for indefinite Sigma. Eigenvalues of Sigma must exceed -tol times its spectral radius. diag(Sigma) must be positive regardless of tol, as standard deviations are handled on a logarithmic scale.

cstart

a number indicating a threshold value of cumulative incidence. Left endpoints of suggested fitting windows are those times when cumulative incidence first exceeds this threshold.

tend

a positive number. Simulated time series run from time 0 to time tend with unit spacing. For nonlinear models of expected cumulative incidence with inflections, this argument is ignored and set to tinfl+1, where tinfl is the time of inflection.

...

unused optional arguments.

Value

A list inheriting from class simulate.egf_model, with elements:

model

copy of argument object.

formula_ts

a formula, always cbind(time, x) ~ ts, expressing how simulated time series are stored in data_ts.

formula_windows

a formula, always cbind(start, end) ~ ts, expressing how fitting window endpoints are stored in data_windows.

formula_parameters

a formula specifying the generative model. If Sigma = NULL, then the formula is ~1 if nsim = 1 and ~ts if nsim > 1. Otherwise, it is ~(1 | ts).

data_ts

a data frame with variables ts, time, and x storing nsim simulated time series in long format.

data_windows

a data frame with nsim rows and variables ts, start, and end suggesting fitting window endpoints for each simulated time series. Start times are determined by cstart. End times are always the last time point in the corresponding time series.

init

a named list of the form list(beta, theta) giving the full bottom level parameter vector of the generative model.

Y

a numeric matrix with nsim rows and length(mu) columns listing top level nonlinear model parameter values for each time series. If Sigma = NULL, then the row vectors of are all mu. Otherwise, Y is (conceptually) the result of MASS::mvrnorm(nsim, mu, Sigma, tol).

call

the call to simulate, allowing for updates to the simulate.egf_model object via update.

Attribute RNGstate preserves the RNG state prior to simulation, making the result reproducible.

See Also

The generic function simulate.

Examples

r <- 0.04
c0 <- 400
s <- 0.2

mu <- log(c(r, c0))
Sigma <- diag(rep.int(s^2, length(mu)))

zz <- simulate(object = egf_model(curve = "exponential", family = "pois"),
               nsim = 20L,
               seed = 202737L,
               mu = mu,
               Sigma = Sigma,
               cstart = 10)
str(zz)

mm <- egf(zz)
(pp <- cbind(actual = coef(zz), fitted = coef(mm)))

[Package epigrowthfit version 0.15.3 Index]