Generate synthetic continuous-indicator data with known latent profile structure. All distributional parameters are explicitly specified so that parameter recovery can be verified in tests.
Arguments
- means
Numeric matrix of dimension
n_vars x n_profiles. Each column is the vector of variable means for that profile.- sds
Numeric matrix of dimension
n_vars x n_profiles, or a scalar / vector recycled to that shape. Standard deviations within each profile for each variable. All values must be positive.- props
Numeric vector of length
n_profiles. Mixing proportions. Need not sum to 1 – normalised internally.- n
Positive integer. Total sample size.
- seed
Integer or NULL. Random seed for reproducibility.
Value
A named list with elements:
datadata.frame with columns
y1...ypandtrue_profile(integer 1...K).paramslist with
means,sds(full matrix), andprops(as supplied, un-normalised).
Examples
means <- matrix(c(0, 0, 10, 10), nrow = 2, ncol = 2)
r <- simulate_lpa(means = means, sds = 0.5, props = c(0.5, 0.5), n = 200, seed = 1)
r$data # data.frame
#> y1 y2 true_profile
#> 1 9.689816661 10.446836851 2
#> 2 10.021057937 9.476350925 2
#> 3 -0.455460824 0.985668693 1
#> 4 0.079014386 -0.191816053 1
#> 5 9.672707678 10.827072651 2
#> 6 0.883643635 0.756106347 1
#> 7 0.358353738 0.041482867 1
#> 8 0.455087115 0.283610457 1
#> 9 0.192092679 -0.512274240 1
#> 10 10.841088040 10.161503252 2
#> 11 9.682131773 10.521806229 2
#> 12 9.769177635 10.049539243 2
#> 13 0.716141119 -0.227068455 1
#> 14 9.674651823 9.672109074 2
#> 15 -0.103690372 -0.017961211 1
#> 16 9.803596035 10.534580730 2
#> 17 -0.159996434 -0.241987465 1
#> 18 -0.139556651 -0.060505056 1
#> 19 10.247094166 9.352929998 2
#> 20 -0.088665241 0.247156418 1
#> 21 -0.252978731 0.653950760 1
#> 22 10.671519413 10.748520505 2
#> 23 -0.107289704 0.407351365 1
#> 24 9.910221735 9.065105605 2
#> 25 9.949904629 10.241014752 2
#> 26 10.356333154 10.228067802 2
#> 27 9.963217798 9.823299857 2
#> 28 9.981182914 10.085244735 2
#> 29 -0.340830239 -0.432017977 1
#> 30 9.837864864 10.339615387 2
#> 31 10.030080220 9.836449493 2
#> 32 -0.294447243 -0.784541093 1
#> 33 10.265748096 9.816274622 2
#> 34 9.240802959 10.682217465 2
#> 35 0.153278930 -0.167140682 1
#> 36 -0.768224912 0.366375021 1
#> 37 -0.150488063 0.473292820 1
#> 38 9.735860048 10.002199352 2
#> 39 -0.326047390 -0.176161153 1
#> 40 9.971551611 9.735152245 2
#> 41 -0.957179713 0.369794613 1
#> 42 0.588291656 -0.531728708 1
#> 43 -0.832486218 0.123105422 1
#> 44 -0.231765201 -0.144749683 1
#> 45 -0.557960053 -1.132444678 1
#> 46 -0.375409501 -0.704425228 1
#> 47 11.043583273 10.458009664 2
#> 48 10.008697810 9.904360525 2
#> 49 -0.643150265 0.401641608 1
#> 50 -0.820302767 0.943737232 1
#> 51 10.225093551 10.736940591 2
#> 52 -0.009279916 0.338634246 1
#> 53 9.840965813 10.189981343 2
#> 54 9.535318926 9.903600787 2
#> 55 9.256269845 10.788945897 2
#> 56 9.462403852 10.298117055 2
#> 57 10.500014402 9.413211530 2
#> 58 -0.310633347 -0.077821267 1
#> 59 -0.692213424 -0.959454910 1
#> 60 10.934645311 9.902370577 2
#> 61 0.212550189 -1.296163835 1
#> 62 9.880676450 10.657001084 2
#> 63 10.529241524 9.682228499 2
#> 64 10.443211326 9.785010581 2
#> 65 -0.309621524 -0.084659166 1
#> 66 11.103051232 10.306109087 2
#> 67 9.872486485 10.339170089 2
#> 68 -0.712247325 0.283975986 1
#> 69 9.927800199 9.713728698 2
#> 70 0.103769170 -0.681645628 1
#> 71 11.153989200 9.805638878 2
#> 72 0.052901184 0.138957066 1
#> 73 10.228499403 9.588459439 2
#> 74 9.961423532 9.965579533 2
#> 75 9.832999579 9.416168837 2
#> 76 -0.017363014 -0.004154507 1
#> 77 0.393819803 0.064427701 1
#> 78 11.037622504 9.927062186 2
#> 79 0.513696219 -0.081955478 1
#> 80 0.603954199 0.881776001 1
#> 81 9.384338289 10.381293256 2
#> 82 0.491947785 0.555715540 1
#> 83 10.109962402 9.538396524 2
#> 84 9.266374985 10.082170919 2
#> 85 0.260511371 0.577412594 1
#> 86 9.920622698 9.971739288 2
#> 87 0.732293656 -1.064680324 1
#> 88 9.616959000 10.172422881 2
#> 89 9.784894123 9.047522277 2
#> 90 9.536945251 9.594414923 2
#> 91 9.911448019 10.662002161 2
#> 92 10.201005890 10.307818425 2
#> 93 -0.365874087 0.545834478 1
#> 94 0.415186584 0.153302431 1
#> 95 -0.604041393 -0.055079381 1
#> 96 -0.523992206 -0.462156387 1
#> 97 10.720578853 10.796456877 2
#> 98 9.492076267 10.022505299 2
#> 99 0.205987356 -0.357564200 1
#> 100 -0.190538026 0.432611550 1
#> 101 0.204700920 0.537220479 1
#> 102 10.844436643 10.947827387 2
#> 103 10.793294217 9.698501348 2
#> 104 -0.165453900 -0.195433910 1
#> 105 -1.142617768 -0.208111016 1
#> 106 11.248830795 9.812171289 2
#> 107 10.333533083 9.816684527 2
#> 108 10.270663668 9.852161274 2
#> 109 -0.006699762 0.720910205 1
#> 110 0.255054211 -0.348769146 1
#> 111 -0.082187916 -0.194083753 1
#> 112 0.210347322 0.326268226 1
#> 113 9.799876628 10.562386223 2
#> 114 9.314896061 9.613944598 2
#> 115 10.493919134 9.745956892 2
#> 116 10.759872513 10.261810295 2
#> 117 -0.154370285 0.508877113 1
#> 118 9.373355122 9.874417706 2
#> 119 10.321120653 9.285003276 2
#> 120 -0.022354568 0.854560516 1
#> 121 -0.866609203 0.717534786 1
#> 122 10.001065930 9.644814427 2
#> 123 9.684849833 9.967466213 2
#> 124 9.829515710 9.120265632 2
#> 125 -0.578286181 0.284861486 1
#> 126 10.901570954 10.806173399 2
#> 127 -0.165566018 -0.818640324 1
#> 128 9.197243294 9.610215743 2
#> 129 10.098596719 9.679411533 2
#> 130 0.131587823 -0.340565697 1
#> 131 -0.492913350 -1.016642798 1
#> 132 8.555539664 10.250481780 2
#> 133 9.679759149 9.234100930 2
#> 134 0.285253818 -0.012498820 1
#> 135 -0.029861638 0.296492361 1
#> 136 -0.049089372 -0.099097711 1
#> 137 0.280410364 0.446004196 1
#> 138 -0.593229319 -0.012857535 1
#> 139 0.548388522 -0.323830225 1
#> 140 -0.002672014 0.323179708 1
#> 141 0.353655334 -0.216916370 1
#> 142 0.517053867 0.886305592 1
#> 143 10.111740207 9.990870144 2
#> 144 9.560646194 10.426407497 2
#> 145 0.581482278 0.102581452 1
#> 146 8.999917528 8.495975701 2
#> 147 9.727604630 9.316944034 2
#> 148 -0.127835355 -0.212051130 1
#> 149 9.916939482 10.118401832 2
#> 150 0.510231954 -1.171361560 1
#> 151 0.068110947 0.480848317 1
#> 152 0.203583802 -0.302212867 1
#> 153 9.965172593 9.623561360 2
#> 154 9.876167829 9.222194204 2
#> 155 0.347775403 -0.726946869 1
#> 156 10.573114179 10.028165918 2
#> 157 -1.201548107 0.254684703 1
#> 158 10.286369778 8.951058520 2
#> 159 10.187362203 9.497819010 2
#> 160 9.787366139 10.267885861 2
#> 161 10.475506404 9.773481458 2
#> 162 -0.194618591 1.082684251 1
#> 163 9.857834669 10.622873336 2
#> 164 0.428704889 0.297749017 1
#> 165 0.859813650 0.002442225 1
#> 166 10.135027450 10.139680391 2
#> 167 9.788907995 9.647046937 2
#> 168 9.405443353 10.314008576 2
#> 169 -0.165516489 0.740106980 1
#> 170 9.530085337 10.541714955 2
#> 171 -0.129466292 -0.406622128 1
#> 172 0.197189584 -0.809438425 1
#> 173 -0.425928546 -0.054827850 1
#> 174 11.324583441 10.220444685 2
#> 175 10.078005838 10.675496990 2
#> 176 0.565103634 -0.659304742 1
#> 177 -1.144561990 0.182192296 1
#> 178 0.370500579 0.116749918 1
#> 179 -0.658122580 0.596977631 1
#> 180 0.459901839 -0.013954986 1
#> 181 10.199065078 9.821350573 2
#> 182 9.796235710 9.426592932 2
#> 183 0.662129315 -0.258710242 1
#> 184 -0.350615835 -0.181061886 1
#> 185 -0.290307152 1.175277163 1
#> 186 9.499463909 11.223265688 2
#> 187 -0.334089303 -0.083351640 1
#> 188 0.472592477 -0.521833720 1
#> 189 0.216851075 -0.986467467 1
#> 190 0.502579609 0.257335817 1
#> 191 -0.195059332 -0.545286792 1
#> 192 10.188185146 11.142329663 2
#> 193 10.122082462 9.557191214 2
#> 194 -0.713128671 0.055553215 1
#> 195 10.889214644 11.905138340 2
#> 196 0.067223830 -0.554454999 1
#> 197 10.382799500 10.153783312 2
#> 198 0.477568338 -0.553447236 1
#> 199 9.974717149 10.173826824 2
#> 200 -0.152907710 -0.436632268 1
r$params # ground-truth parameters
#> $means
#> [,1] [,2]
#> [1,] 0 10
#> [2,] 0 10
#>
#> $sds
#> [,1] [,2]
#> [1,] 0.5 0.5
#> [2,] 0.5 0.5
#>
#> $props
#> [1] 0.5 0.5
#>