Learn R Programming

bizicount (version 1.3.3)

simulate.zicreg: Simulating response values from fitted univariate zero-inflated count regression model

Description

Simulates responses using the fitted parameters from a zicreg-class object, as returned by zic.reg. Primarily useful for methods found in DHARMa package. See 'Examples.'

Usage

# S3 method for zicreg
simulate(object, nsim = 250, seed = 123, ...)

Value

A numeric \(n x nsim\) matrix, with rows indexing observations, and columns indexing the simulation number.

Arguments

object

A zicreg-class model object, as returned by zic.reg.

nsim

Number of simulated datasets to create.

seed

Random seed for random number generation in simulations. If NULL, no seed is set.

...

Ignored.

Author

John Niehaus

References

Florian Hartig (2022). DHARMa: Residual Diagnostics for Hierarchical (Multi-Level / Mixed) Regression Models. R package version 0.4.5. https://CRAN.R-project.org/package=DHARMa

Examples

Run this code
# Simulate some zip data
n=300
x = cbind(1, rnorm(n))
z = cbind(1, rbeta(n, 4, 8))
b = c(1, 2.2)
g = c(-1, 1.7)
lam = exp(x %*% b)
psi = plogis(z %*% g)

y = bizicount::rzip(n, lambda = lam, psi=psi)
dat = cbind.data.frame(x = x[,-1], z = z[,-1], y = y)

# estimate model

mod = zic.reg(y ~ x | z, data = dat, keep = TRUE)

# simulate from fit for use in dharma
sims = simulate(mod)

### Make dharma object

dharm = DHARMa::createDHARMa(
     simulatedResponse = sims,
     observedResponse = y,
     fittedPredictedResponse = fitted(mod),
     integerResponse = TRUE,
     method = "PIT"
)

### Plot the DHARMa object, do other diagnostics
plot(dharm)
DHARMa::testResiduals(dharm)

Run the code above in your browser using DataLab