simulate.zicreg {bizicount}R Documentation

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 class 'zicreg'
simulate(object, nsim = 250, seed = 123, ...)

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.

Value

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

Author(s)

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

# 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)

[Package bizicount version 1.3.2 Index]