
Simulated draws from model coefficients
Source:R/5_simulate_model.R
, R/methods_glmmTMB.R
simulate_model.Rd
Simulate draws from a statistical model to return a data frame of estimates.
Usage
simulate_model(model, iterations = 1000, ...)
# S3 method for glmmTMB
simulate_model(
model,
iterations = 1000,
component = c("all", "conditional", "zi", "zero_inflated", "dispersion"),
verbose = FALSE,
...
)
Arguments
- model
Statistical model (no Bayesian models).
- iterations
The number of draws to simulate/bootstrap.
- ...
Arguments passed to
insight::get_varcov()
, e.g. to allow simulated draws to be based on heteroscedasticity consistent variance covariance matrices.- component
Should all parameters, parameters for the conditional model, for the zero-inflation part of the model, or the dispersion model be returned? Applies to models with zero-inflation and/or dispersion component.
component
may be one of"conditional"
,"zi"
,"zero-inflated"
,"dispersion"
or"all"
(default). May be abbreviated.- verbose
Toggle warnings and messages.
Details
Technical Details
simulate_model()
is a computationally faster alternative
to bootstrap_model()
. Simulated draws for coefficients are based
on a multivariate normal distribution (MASS::mvrnorm()
) with mean
mu = coef(model)
and variance Sigma = vcov(model)
.
Models with Zero-Inflation Component
For models from packages glmmTMB, pscl, GLMMadaptive and
countreg, the component
argument can be used to specify
which parameters should be simulated. For all other models, parameters
from the conditional component (fixed effects) are simulated. This may
include smooth terms, but not random effects.
Examples
model <- lm(Sepal.Length ~ Species * Petal.Width + Petal.Length, data = iris)
head(simulate_model(model))
#> (Intercept) Speciesversicolor Speciesvirginica Petal.Width Petal.Length
#> 1 3.395221 -1.2536580 -1.777932 0.65221378 0.9583286
#> 2 3.327990 -0.9353353 -3.427441 -0.03128756 1.1998311
#> 3 3.568873 -1.0901020 -1.879757 0.61405394 0.8676523
#> 4 3.410203 -1.4316679 -2.179421 0.71641958 0.9852405
#> 5 3.373303 -0.9242895 -2.209280 0.93071348 0.9568807
#> 6 3.532191 -1.1864037 -2.000635 0.98681239 0.8493350
#> Speciesversicolor:Petal.Width Speciesvirginica:Petal.Width
#> 1 -0.8673931 -0.81436196
#> 2 -1.1534225 0.02533333
#> 3 -0.7723600 -0.55922211
#> 4 -0.9191681 -0.74420141
#> 5 -1.3409819 -0.90899289
#> 6 -1.0368742 -0.79739037
# \donttest{
if (require("glmmTMB", quietly = TRUE)) {
model <- glmmTMB(
count ~ spp + mined + (1 | site),
ziformula = ~mined,
family = poisson(),
data = Salamanders
)
head(simulate_model(model))
head(simulate_model(model, component = "zero_inflated"))
}
#> (Intercept) minedno
#> 1 0.1845184 -1.346765
#> 2 0.7287636 -1.704010
#> 3 1.2110542 -2.118863
#> 4 0.4841667 -1.406178
#> 5 0.4262444 -1.428976
#> 6 0.6211372 -1.444925
# }