Simulates data based on a specified slca
model. If the model parameters are not already estimated, they can either be provided by the user or generated randomly.
Usage
# S3 method for class 'slca'
simulate(object, nsim = 500, seed = NULL, parm, nlevel, ...)
Arguments
- object
an
slca
object representing the model from which data will be simulated.- nsim
an integer specifying the number of response observations to simulate. The default is 500.
- seed
an integer specifying the random seed for reproducibility. If not provided, results will vary across runs.
- parm
a user-specified set of parameters to guide the simulation. This is required if the model has not been previously estimated.
- nlevel
an integer or integer vector specifying the number of levels for each manifest item in the model. If a single integer is provided, all manifest items will have the same number of levels. The default is 2.
- ...
Additional arguments passed to other methods.
Value
A list
with the following components:
- class
A
data.frame
containing the assigned latent class for each individual across all latent class variables.- response
A
data.frame
containing the simulated manifest item responses.
Examples
m1 <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5,
lc2[4] ~ y1 + y2 + y3 + y4 + y5)
sim <- simulate(m1, 1000)
sapply(sim$class, table)
#> $lc1
#>
#> 1 2 3
#> 165 302 533
#>
#> $lc2
#>
#> 1 2 3 4
#> 50 202 430 318
#>
# simulate data with defined number of levels of manifest items
m2 <- slca(lc1[3] ~ x1 + x2 + x3 + x4)
sim <- simulate(m2, nlevel = c(3, 3, 3, 3))
d <- sim$response
sapply(d, table)
#> x1 x2 x3 x4
#> 1 142 105 138 21
#> 2 156 186 262 189
#> 3 202 209 100 290
sim <- simulate(m2, nlevel = c(x1 = 2, x3 = 3, x4 = 4, x5 = 5))
d <- sim$response
sapply(d, table)
#> $x1
#>
#> 1 2
#> 248 252
#>
#> $x2
#>
#> 1 2 3
#> 185 97 218
#>
#> $x3
#>
#> 1 2 3 4
#> 150 55 164 131
#>
#> $x4
#>
#> 1 2 3 4 5
#> 120 149 98 83 50
#>
# simulate data with user-defined parameters
pi <- rep(1 / 3, 3)
rho <- c(.9, .1, .9, .1, .9, .1, .9, .1,
.9, .1, .9, .1, .1, .9, .1, .9,
.1, .9, .1, .9, .1, .9, .1, .9)
par <- c(pi, rho)
m3 <- slca(lc[3] ~ y1 + y2 + y3 + y4)
sim <- simulate(m3, parm = par)
mf <- estimate(m3, sim$response)
param(mf)
#> PI :
#> (lc)
#> class
#> 1 2 3
#> 0.2588 0.4751 0.2661
#>
#> RHO :
#> (a)
#> class
#> response 1 2 3
#> 1(V1) 0.9355 0.8417 0.0000
#> 2 0.0645 0.1583 1.0000
#> 1(V2) 0.9304 0.8032 0.0360
#> 2 0.0696 0.1968 0.9640
#> 1(V3) 1.0000 0.1848 0.0653
#> 2 0.0000 0.8152 0.9347
#> 1(V4) 0.9890 0.1957 0.0791
#> 2 0.0110 0.8043 0.9209
#>
#> V1 V2 V3 V4
#> lc y1 y2 y3 y4