This function simulates data from a constructed slca
model. If the model is not already estimated, parameters can be specified by the user or generated randomly.
Usage
# S3 method for class 'slca'
simulate(object, nsim = 500, seed = NULL, parm, nlevel, ...)
Arguments
- object
a
slca
object representing the model from which data will be simulated.- nsim
the number of response observations to simulate. Defaults to 500.
- seed
a random seed for reproducibility of the
- parm
a set of parameters provided by the user to guide the simulation, if the model has not been estimated.
- nlevel
the number of levels for each manifest item declared in the model. If not provided, the default is 2.
- ...
additional arguments.
Value
A list
of two components:
- class
A
data.frame
providing the assigned latent class for each individual across different latent class variables.- response
A
data.frame
containing the manifest items that were simulated.
Examples
library(magrittr)
model <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5)
sim_data <- model %>% simulate(nlevel = c(3, 3, 3, 3, 3))
y <- sim_data$response
sapply(y, table)
#> x1 x2 x3 x4 x5
#> 1 114 341 182 192 105
#> 2 210 78 54 259 189
#> 3 176 81 264 49 206
sim_data <- model %>%
simulate(nlevel = c(x1 = 2, x3 = 3, x4 = 4, x5 = 5))
y <- sim_data$response
sapply(y, table)
#> $x1
#>
#> 1 2
#> 266 234
#>
#> $x2
#>
#> 1 2
#> 326 174
#>
#> $x3
#>
#> 1 2 3
#> 35 277 188
#>
#> $x4
#>
#> 1 2 3 4
#> 187 22 57 234
#>
#> $x5
#>
#> 1 2 3 4 5
#> 66 186 95 117 36
#>
model <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5,
lc2[4] ~ y1 + y2 + y3 + y4 + y5)
sim_data <- model %>% simulate(1000)
sapply(sim_data$class, table)
#> $lc1
#>
#> 1 2 3
#> 74 19 907
#>
#> $lc2
#>
#> 1 2 3 4
#> 437 406 26 131
#>