Skip to contents

Draws nsim replicate response vectors from the fitted category probabilities at the estimation data, in the format of stats::simulate(). The main consumer is simulated-residual diagnostics:


sims <- simulate(fit, nsim = 250)
DHARMa::createDHARMa(simulatedResponse = as.matrix(sims),
                     observedResponse  = fit$y,
                     fittedPredictedResponse = as.numeric(fitted(fit) %*% (0:(fit$J - 1))),
                     integerResponse = TRUE)

Responses are returned as integers 0..J-1 (the internal category index; fit$levels maps them to labels), which is what DHARMa expects.

Usage

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

Arguments

object

An "iord" object.

nsim

Number of replicate response vectors.

seed

Optional seed, handled as in stats::simulate().

...

Unused.

Value

A data frame with nsim integer columns, one row per observation, with a "seed" attribute.

See also

residuals.iord(), riop() for drawing from a chosen data-generating process, predict.iord().

Other simulation and diagnostics: iord-distribution, residuals.iord(), riop()

Examples

set.seed(1)
d <- riop(300, beta = c(0.8, -0.4), tau = c(-0.5, 0.6), gamma = c(0.5, 0.8), inflate = "bottom")
m <- iop(y ~ x1 + x2 | z1, data = d, inflate = "bottom")
s <- simulate(m, nsim = 3)
table(s$sim_1)
#> 
#>   0   1   2 
#> 174  64  62