Learn R Programming

slca (version 1.0.0)

simulate.slca: Simulate data from slca model.

Description

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 slca
simulate(object, nsim = 500, seed = NULL, parm, nlevel, ...)

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.

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.

Examples

Run this code
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)

sim_data <- model %>%
   simulate(nlevel = c(x1 = 2, x3 = 3, x4 = 4, x5 = 5))
y <- sim_data$response
sapply(y, table)

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)

Run the code above in your browser using DataLab