simulate_lcm_given_tree {ddtlcm}R Documentation

Simulate multivariate binary responses from a latent class model given a tree

Description

Generate multivariate binary responses from the following process: For individual i = 1, ..., N, Z_i ~ Categorical_K(prior_class_probability) For item j = 1, ..., J, Y_{ij} | Z_i = k ~ Binomial(class_item_probability_{kj})

Usage

simulate_lcm_given_tree(
  tree_phylo,
  N,
  class_probability = 1,
  item_membership_list,
  Sigma_by_group = NULL,
  root_node_location = 0,
  seed_parameter = 1,
  seed_response = 1
)

Arguments

tree_phylo

a "phylo" tree with K leaves

N

number of individuals

class_probability

a length K vector, where the k-th element is the probability of assigning an individual to class k. It does not have to sum up to 1

item_membership_list

a list of G elements, where the g-th element contains the column indices of the observed data matrix corresponding to items in major group g

Sigma_by_group

a length-G vector for the posterior mean group-specific diffusion variances.

root_node_location

the coordinate of the root node parameter. By default, the node parameter initiates at the origin so takes value 0. If a value, then the value will be repeated into a length J vector. If a vector, it must be of length J.

seed_parameter

an integer random seed to generate parameters given the tree

seed_response

an integer random seed to generate multivariate binary observations from LCM

Value

a named list of the following elements:

tree_with_parameter

a "phylo4d" tree with K leaves.

response_prob

a K by J matrix, where the k,j-th element is the response probability of item j for individuals in class k

response_matrix

a K by J matrix with entries between 0 and 1 for the item response probabilities.

class_probability

a K-vector with entries between 0 and 1 for the class probabilities. Entries should be nonzero and sum up to 1, or otherwise will be normalized

class_assignments

a N-vector with integer entries from 1, ..., K. The initial values for individual class assignments.

Sigma_by_group

a G-vector greater than 0. The initial values for the group-specific diffusion variances.

c

a value greater than 0. The initial values for the group-specific diffusion variances.

item_membership_list

same as input

See Also

Other simulate DDT-LCM data: simulate_DDT_tree(), simulate_lcm_response(), simulate_parameter_on_tree()

Examples

# load the MAP tree structure obtained from the real HCHS/SOL data
data(parameter_diet)
# unlist the elements into variables in the global environment
list2env(setNames(parameter_diet, names(parameter_diet)), envir = globalenv()) 
# number of individuals
N <- 496
# set random seed to generate node parameters given the tree
seed_parameter = 1
# set random seed to generate multivariate binary observations from LCM
seed_response = 1
# simulate data given the parameters
sim_data <- simulate_lcm_given_tree(tree_phylo, N, 
                                    class_probability, item_membership_list, Sigma_by_group, 
                                    root_node_location = 0, seed_parameter = 1, seed_response = 1)

[Package ddtlcm version 0.2.1 Index]