Skip to contents

simulate() draws new response values from the fitted drmTMB model. For univariate Gaussian models with known sampling covariance, simulation uses the total observation covariance implied by the known sampling covariance plus the fitted residual scale. For Student-t models, simulation uses fitted mu, sigma, and nu. For lognormal models, simulation uses fitted log-scale mu and sigma. For Gamma models, simulation uses fitted mean mu and coefficient of variation sigma. For beta models, simulation uses fitted mean mu and public scale sigma with internal phi = 1 / sigma^2. For beta-binomial models, simulation draws latent success probabilities from the fitted beta distribution and then success counts from the stored trial denominators. For cumulative-logit ordinal models, simulation draws ordered categories from the fitted cumulative-logit probabilities. For Poisson models, simulation uses the fitted mean mu. For zero-inflated Poisson models, simulation uses fitted conditional mean mu and structural-zero probability zi. For negative-binomial 2 models, simulation uses fitted mu and overdispersion scale sigma, with Var(y) = mu + sigma^2 * mu^2; zero-truncated NB2 models draw from this NB2 component conditional on positive counts. The zero-inflated NB2 path adds structural-zero probability zi; the hurdle NB2 path adds hurdle-zero probability hu and draws nonzero counts from the zero-truncated NB2 component. For bivariate Gaussian models without known sampling covariance, simulation uses the fitted mu1, mu2, sigma1, sigma2, and residual rho12. If a dense bivariate known V was supplied, simulation uses the full row-paired observation covariance V + Omega.

Usage

# S3 method for class 'drmTMB'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

A drmTMB fit.

nsim

Number of simulated data sets.

seed

Optional random-number seed. The previous .Random.seed state is restored after simulation.

...

Reserved for future simulation options.

Value

A data frame. Univariate models return one column per simulation. Bivariate models return paired columns named sim_<j>_y1 and sim_<j>_y2.

Examples

dat <- data.frame(y = c(0.2, 0.5, 1.1, 1.4), x = c(-1, 0, 1, 2))
fit <- drmTMB(bf(y ~ x, sigma ~ 1), data = dat)
simulate(fit, nsim = 2, seed = 1)
#>       sim_1     sim_2
#> 1 0.1279762 0.1921041
#> 2 0.6023192 0.5349613
#> 3 0.9539444 1.0426978
#> 4 1.5370148 1.4795284