View source: R/zicreg-methods.R
simulate.zicreg | R Documentation |
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.'
## S3 method for class 'zicreg'
simulate(object, nsim = 250, seed = 123, ...)
object |
A |
nsim |
Number of simulated datasets to create. |
seed |
Random seed for random number generation in simulations. If
|
... |
Ignored. |
A numeric n x nsim
matrix, with rows indexing
observations, and columns indexing the simulation number.
John Niehaus
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
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.