|
| 1 | +# simcdm: Simulate Cognitive Diagnostic Model Data {#simcdm} |
| 2 | + |
| 3 | +```{r load-r-pkg, include = FALSE} |
| 4 | +library(simcdm) |
| 5 | +``` |
| 6 | + |
| 7 | +## Matrix Simulation |
| 8 | + |
| 9 | +Simulations within this section are done underneath the following settings. |
| 10 | + |
| 11 | +```{r setup-matrix-sims} |
| 12 | +# Set a seed for reproducibility |
| 13 | +set.seed(888) |
| 14 | +# Setup Parameters |
| 15 | +N = 15 # Number of Examinees / Subjects |
| 16 | +J = 10 # Number of Items |
| 17 | +K = 2 # Number of Skills / Attributes |
| 18 | +``` |
| 19 | + |
| 20 | +### Identifiable Q Matrix Simulation |
| 21 | + |
| 22 | +Simulate an identifiable $Q$ matrix ($J$ items by $K$ skills). |
| 23 | + |
| 24 | +```{r sim-q-matrix} |
| 25 | +# Set a seed for reproducibility |
| 26 | +set.seed(1512) |
| 27 | +# Simulate an identifiable Q matrix |
| 28 | +Q = sim_q_matrix(J, K) |
| 29 | +Q |
| 30 | +``` |
| 31 | + |
| 32 | +### $\eta$ Matrix Simulation |
| 33 | + |
| 34 | +Create the ideal response matrix for each trait ($J$ items by $2^K$ latent classes). |
| 35 | + |
| 36 | +```{r sim-eta-matrix} |
| 37 | +# Set a seed for reproducibility |
| 38 | +set.seed(4421) |
| 39 | +# Simulate an eta matrix |
| 40 | +eta = sim_eta_matrix(K, J, Q) |
| 41 | +eta |
| 42 | +``` |
| 43 | + |
| 44 | +### Attribute profile simulation |
| 45 | + |
| 46 | +Generate latent attribute profile classes ($2^K$ latent classes by $K$ skills). |
| 47 | + |
| 48 | +```{r attribute-classes-gen} |
| 49 | +# Create a listing of all attribute classes |
| 50 | +class_alphas = attribute_classes(K) |
| 51 | +class_alphas |
| 52 | +``` |
| 53 | + |
| 54 | +Generate latent attribute profile class for each subject ($N$ subjects by $K$ skills). |
| 55 | + |
| 56 | +```{r sim-subject-attributes} |
| 57 | +# Set a seed for reproducibility |
| 58 | +set.seed(5126) |
| 59 | +# Create attributes for a subject |
| 60 | +subject_alphas = sim_subject_attributes(N, K) |
| 61 | +subject_alphas |
| 62 | +# Equivalent to: |
| 63 | +# subject_alphas = class_alphas[sample(2 ^ K, N, replace = TRUE),] |
| 64 | +``` |
| 65 | + |
| 66 | +### DINA Simulation |
| 67 | + |
| 68 | +Simulations within this section are done underneath the following settings. |
| 69 | + |
| 70 | +```{r setup-sim-dina} |
| 71 | +# Set a seed for reproducibility |
| 72 | +set.seed(888) |
| 73 | +# Setup Parameters |
| 74 | +N = 15 # Number of Examinees / Subjects |
| 75 | +J = 10 # Number of Items |
| 76 | +K = 2 # Number of Skills / Attributes |
| 77 | +# Assign slipping and guessing values for each item |
| 78 | +ss = gs = rep(.2, J) |
| 79 | +# Simulate identifiable Q matrix |
| 80 | +Q = sim_q_matrix(J, K) |
| 81 | +# Simulate subject attributes |
| 82 | +subject_alphas = sim_subject_attributes(N, K) |
| 83 | +``` |
| 84 | + |
| 85 | +### DINA Item Simulation |
| 86 | + |
| 87 | +Simulate item data, $Y$, under DINA model ($N$ by $J$) |
| 88 | + |
| 89 | +```{r sim-dina-items} |
| 90 | +# Set a seed for reproducibility |
| 91 | +set.seed(2019) |
| 92 | +# Simulate items under the DINA model |
| 93 | +items_dina = sim_dina_items(subject_alphas, Q, ss, gs) |
| 94 | +items_dina |
| 95 | +``` |
| 96 | + |
| 97 | +### DINA Attribute Simulation |
| 98 | + |
| 99 | +Simulate attribute data under DINA model ($N$ by $J$) |
| 100 | + |
| 101 | +```{r sim-dina-attributes} |
| 102 | +# Set a seed for reproducibility |
| 103 | +set.seed(51823) |
| 104 | +# Simulate attributes under the DINA model |
| 105 | +attributes = sim_dina_attributes(subject_alphas, Q) |
| 106 | +attributes |
| 107 | +``` |
| 108 | + |
| 109 | +## rRUM Simulation |
| 110 | + |
| 111 | +The rRUM simulations are done using the following settings. |
| 112 | + |
| 113 | +```{r rrum-sim-setup} |
| 114 | +# Set a seed for reproducibility |
| 115 | +set.seed(888) |
| 116 | +# Setup Parameters |
| 117 | +N = 15 # Number of Examinees / Subjects |
| 118 | +J = 10 # Number of Items |
| 119 | +K = 2 # Number of Skills / Attributes |
| 120 | +# The probabilities of answering each item correctly for individuals |
| 121 | +# who do not lack any required attribute |
| 122 | +pistar = rep(.9, J) |
| 123 | +# Simulate an identifiable Q matrix |
| 124 | +Q = sim_q_matrix(J, K) |
| 125 | +# Penalties for failing to have each of the required attributes |
| 126 | +rstar = .5 * Q |
| 127 | +# Latent Class Probabilities |
| 128 | +pis = c(.1, .2, .3, .4) |
| 129 | +# Generate latent attribute profile with custom probability (N subjects by K skills) |
| 130 | +subject_alphas = sim_subject_attributes(N, K, prob = pis) |
| 131 | +# Equivalent to: |
| 132 | +# class_alphas = attribute_classes(K) |
| 133 | +# subject_alphas = class_alphas[sample(2 ^ K, N, replace = TRUE, prob = pis),] |
| 134 | +``` |
| 135 | + |
| 136 | +### Simulate rRUM items |
| 137 | + |
| 138 | +Simulate rRUM item data $Y$ ($N$ by $J$) |
| 139 | + |
| 140 | +```{r sim-rrum} |
| 141 | +# Set a seed for reproducibility |
| 142 | +set.seed(912) |
| 143 | +# Generate rRUM items |
| 144 | +rrum_items = sim_rrum_items(Q, rstar, pistar, subject_alphas) |
| 145 | +rrum_items |
| 146 | +``` |
| 147 | + |
0 commit comments