Simulate draws from a statistical model to return a data frame of estimates.

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 or from other methods.

component

Should all parameters, parameters for the conditional model, or for the zero-inflated part of the model be returned? Applies to models with zero-inflated component. component may be one of "conditional", "zi", "zero-inflated", "dispersion" or "all" (default). May be abbreviated.

verbose

Toggle warnings and messages.

Value

A data frame.

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.

See also

Examples

library(parameters)
model <- lm(Sepal.Length ~ Species * Petal.Width + Petal.Length, data = iris)
head(simulate_model(model))
#>   (Intercept) Speciesversicolor Speciesvirginica Petal.Width Petal.Length
#> 1    3.662706        -0.9956017        -2.209584  -0.3587959    0.9451276
#> 2    3.647275        -0.6123895        -2.501323  -0.1082739    0.9663680
#> 3    3.504114        -1.4132301        -2.650989   0.2286031    0.9742007
#> 4    3.395503        -1.2891012        -2.343047   0.7040094    0.9899346
#> 5    3.269931        -1.7395932        -2.668695   0.6356595    1.0781432
#> 6    3.278125        -0.5871270        -2.007362   1.4275434    0.9803884
#>   Speciesversicolor:Petal.Width Speciesvirginica:Petal.Width
#> 1                    -0.1868436                    0.2901496
#> 2                    -0.7978578                    0.1586344
#> 3                    -0.4461917                   -0.0389400
#> 4                    -1.0049591                   -0.6809964
#> 5                    -0.7689287                   -0.6236015
#> 6                    -2.1371130                   -1.4734537
# \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"))
}
#> Warning: 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
#> Warning: 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
#> Warning: 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
#>   (Intercept)   minedno
#> 1   0.8381675 -2.195582
#> 2   0.9332055 -1.989318
#> 3   0.2996814 -1.532834
#> 4   0.7315934 -1.785108
#> 5   1.1235214 -2.141896
#> 6   0.5997095 -1.839832
# }