See vignette("sim", package = "glmmTMB") for more details and examples, and vignette("covstruct", package = "glmmTMB") for more information on the parameterization of different covariance structures.

simulate_new(
  object,
  nsim = 1,
  seed = NULL,
  family = gaussian,
  newdata,
  newparams,
  ...,
  show_pars = FALSE
)

Arguments

object

a one-sided model formula (e.g. ~ a + b + c (peculiar naming is for consistency with the generic function, which typically takes a fitted model object)

nsim

number of simulations

seed

random-number seed

family

a family function, a character string naming a family function, or the result of a call to a family function (variance/link function) information. See family for a generic discussion of families or family_glmmTMB for details of glmmTMB-specific families.

newdata

a data frame containing all variables listed in the formula, including the response variable (which needs to fall within the domain of the conditional distribution, and should probably not be all zeros, but whose value is otherwise irrelevant)

newparams

a list of parameters containing sub-vectors (beta, betazi, betadisp, theta, etc.) to be used in the model

...

other arguments to glmmTMB (e.g. family)

show_pars

(logical) print structure of parameter vector and stop without simulating?

Examples

## use Salamanders data for structure/covariates
simulate_new(~ mined + (1|site),
             zi = ~ mined,
             newdata = Salamanders, show_pars  = TRUE)
#>   beta   beta betazi betazi      b      b      b      b      b      b      b 
#>      1      1      0      0      1      1      1      1      1      1      1 
#>      b      b      b      b      b      b      b      b      b      b      b 
#>      1      1      1      1      1      1      1      1      1      1      1 
#>      b      b      b      b      b  betadisp  theta 
#>      1      1      1      1      1      0      0 
sim_count <- simulate_new(~ mined + (1|site),
             newdata = Salamanders,
             zi = ~ mined,
             family = nbinom2,
             newparams = list(beta = c(2, 1),
                         betazi = c(-0.5, 0.5), ## logit-linear model for zi
                         betadisp = log(2), ## log(NB dispersion)
                         theta = log(1)) ## log(among-site SD)
)
#> Warning: non-integer counts in a nbinom2 model
head(sim_count[[1]])
#> [1]  3  5  1  0  0 16