Skip to contents

Simulates subject-level parameters in the format required by make_data().

Usage

make_random_effects(
  design,
  group_means,
  n_subj = NULL,
  variance_proportion = 0.2,
  covariances = NULL
)

Arguments

design

A design list. The design as specified by design()

group_means

A numeric vector. The group level means for each parameter, in the same order as sampled_p_vector(design)

n_subj

An integer. The number of subjects to generate parameters for. If NULL will be inferred from design

variance_proportion

A double. Optional. If covariances are not specified, the variances will be created by multiplying the means by this number. The covariances will be 0.

covariances

A covariance matrix. Optional. Specify the intended covariance matrix.

Value

A matrix of subject-level parameters.

Examples

# First create a design
design_DDMaE <- design(data = forstmann,model=DDM,
                            formula =list(v~0+S,a~E, t0~1, s~1, Z~1, sv~1, SZ~1),
                            constants=c(s=log(1)))
#> Parameter(s) st0 not specified in formula and assumed constant.
#> 
#>  Sampled Parameters: 
#> [1] "v_Sleft"     "v_Sright"    "a"           "a_Eneutral"  "a_Eaccuracy"
#> [6] "t0"          "Z"           "sv"          "SZ"         
#> 
#>  Design Matrices: 
#> $v
#>      S v_Sleft v_Sright
#>   left       1        0
#>  right       0        1
#> 
#> $a
#>         E a a_Eneutral a_Eaccuracy
#>     speed 1          0           0
#>   neutral 1          1           0
#>  accuracy 1          0           1
#> 
#> $t0
#>  t0
#>   1
#> 
#> $s
#>  s
#>  1
#> 
#> $Z
#>  Z
#>  1
#> 
#> $sv
#>  sv
#>   1
#> 
#> $SZ
#>  SZ
#>   1
#> 
#> $st0
#>  st0
#>    1
#> 
# Then create a group-level means vector:
group_means =c(v_Sleft=-2,v_Sright=2,a=log(1),a_Eneutral=log(1.5),a_Eaccuracy=log(2),
               t0=log(.2),Z=qnorm(.5),sv=log(.5),SZ=qnorm(.5))
# Now we can create subject-level parameters
subj_pars <- make_random_effects(design_DDMaE, group_means, n_subj = 5)

# We can also define a covariance matrix to simulate from
subj_pars <- make_random_effects(design_DDMaE, group_means, n_subj = 5,
             covariances = diag(.1, length(group_means)))

# The subject level parameters can be used to generate data
make_data(subj_pars, design_DDMaE, n_trials = 10)
#>     subjects        E     S trials     R        rt
#> 1          1    speed  left      1  left 0.4193612
#> 6          1  neutral  left      1  left 1.3213483
#> 11         1 accuracy  left      1  left 1.0101585
#> 16         1    speed right      1 right 0.9068502
#> 21         1  neutral right      1 right 2.6145269
#> 26         1 accuracy right      1 right 0.6020842
#> 31         1    speed  left      2  left 0.4759412
#> 36         1  neutral  left      2  left 3.6021403
#> 41         1 accuracy  left      2  left 0.9803307
#> 46         1    speed right      2 right 0.5809446
#> 51         1  neutral right      2 right 1.5400219
#> 56         1 accuracy right      2 right 1.1231763
#> 61         1    speed  left      3  left 0.8520405
#> 66         1  neutral  left      3  left 0.6937543
#> 71         1 accuracy  left      3 right 0.8244735
#> 76         1    speed right      3 right 0.3909499
#> 81         1  neutral right      3 right 1.0072313
#> 86         1 accuracy right      3 right 0.4103519
#> 91         1    speed  left      4  left 0.5283641
#> 96         1  neutral  left      4  left 5.9878096
#> 101        1 accuracy  left      4  left 1.8257255
#> 106        1    speed right      4 right 0.4401735
#> 111        1  neutral right      4 right 0.9594493
#> 116        1 accuracy right      4 right 0.8190185
#> 121        1    speed  left      5 right 0.7636714
#> 126        1  neutral  left      5  left 0.7881564
#> 131        1 accuracy  left      5  left 0.7460804
#> 136        1    speed right      5  left 0.5774319
#> 141        1  neutral right      5 right 1.8611451
#> 146        1 accuracy right      5 right 0.4661755
#> 151        1    speed  left      6  left 0.9517008
#> 156        1  neutral  left      6  left 1.3478634
#> 161        1 accuracy  left      6  left 0.5864586
#> 166        1    speed right      6 right 0.6148954
#> 171        1  neutral right      6 right 0.9797640
#> 176        1 accuracy right      6 right 0.9929629
#> 181        1    speed  left      7  left 0.9625560
#> 186        1  neutral  left      7  left 0.9347382
#> 191        1 accuracy  left      7  left 0.5849136
#> 196        1    speed right      7 right 0.4003832
#> 201        1  neutral right      7 right 1.4639503
#> 206        1 accuracy right      7 right 1.4463538
#> 211        1    speed  left      8  left 0.4179070
#> 216        1  neutral  left      8  left 2.1427418
#> 221        1 accuracy  left      8  left 1.0042443
#> 226        1    speed right      8 right 0.4138224
#> 231        1  neutral right      8 right 1.6471585
#> 236        1 accuracy right      8 right 3.0998809
#> 241        1    speed  left      9  left 0.5384385
#> 246        1  neutral  left      9  left 1.7562213
#> 251        1 accuracy  left      9  left 1.1296061
#> 256        1    speed right      9 right 0.4745968
#> 261        1  neutral right      9 right 0.8852778
#> 266        1 accuracy right      9 right 1.0490096
#> 271        1    speed  left     10  left 1.1841024
#> 276        1  neutral  left     10  left 2.1801970
#> 281        1 accuracy  left     10  left 2.9564186
#> 286        1    speed right     10 right 1.8382561
#> 291        1  neutral right     10 right 1.3635594
#> 296        1 accuracy right     10 right 0.9623265
#> 2          2    speed  left      1  left 0.7990223
#> 7          2  neutral  left      1  left 1.1305798
#> 12         2 accuracy  left      1  left 0.8376466
#> 17         2    speed right      1  left 0.8313641
#> 22         2  neutral right      1 right 1.8219549
#> 27         2 accuracy right      1 right 2.1477976
#> 32         2    speed  left      2  left 0.6867480
#> 37         2  neutral  left      2  left 0.6374366
#> 42         2 accuracy  left      2  left 0.5671491
#> 47         2    speed right      2  left 0.5581627
#> 52         2  neutral right      2 right 0.7687573
#> 57         2 accuracy right      2  left 0.5959522
#> 62         2    speed  left      3  left 0.5986936
#> 67         2  neutral  left      3  left 0.5923028
#> 72         2 accuracy  left      3  left 0.5939293
#> 77         2    speed right      3  left 0.5922915
#> 82         2  neutral right      3  left 0.4666529
#> 87         2 accuracy right      3 right 1.0570027
#> 92         2    speed  left      4  left 0.5657949
#> 97         2  neutral  left      4  left 0.6834971
#> 102        2 accuracy  left      4  left 1.0798908
#> 107        2    speed right      4 right 0.8262225
#> 112        2  neutral right      4 right 0.9072218
#> 117        2 accuracy right      4 right 2.7363025
#> 122        2    speed  left      5  left 0.4625597
#> 127        2  neutral  left      5  left 0.6852235
#> 132        2 accuracy  left      5  left 0.5802900
#> 137        2    speed right      5 right 0.8591691
#> 142        2  neutral right      5 right 1.4938257
#> 147        2 accuracy right      5 right 1.0344972
#> 152        2    speed  left      6 right 0.8180158
#> 157        2  neutral  left      6  left 0.5490006
#> 162        2 accuracy  left      6  left 1.8680783
#> 167        2    speed right      6  left 0.5207631
#> 172        2  neutral right      6 right 0.9011335
#> 177        2 accuracy right      6 right 1.2762525
#> 182        2    speed  left      7  left 0.5109791
#> 187        2  neutral  left      7  left 0.7570672
#> 192        2 accuracy  left      7  left 0.9992663
#> 197        2    speed right      7  left 0.6972221
#> 202        2  neutral right      7  left 0.4827839
#> 207        2 accuracy right      7 right 1.2981473
#> 212        2    speed  left      8  left 0.4726421
#> 217        2  neutral  left      8  left 1.1149193
#> 222        2 accuracy  left      8  left 0.8523993
#> 227        2    speed right      8 right 0.9092733
#> 232        2  neutral right      8  left 0.5509334
#> 237        2 accuracy right      8 right 1.2877926
#> 242        2    speed  left      9  left 0.6744828
#> 247        2  neutral  left      9  left 0.6295208
#> 252        2 accuracy  left      9  left 0.6239107
#> 257        2    speed right      9 right 0.8306768
#> 262        2  neutral right      9 right 1.6525868
#> 267        2 accuracy right      9  left 0.5408722
#> 272        2    speed  left     10  left 0.4796214
#> 277        2  neutral  left     10  left 0.6178184
#> 282        2 accuracy  left     10  left 0.6759889
#> 287        2    speed right     10 right 0.6072875
#> 292        2  neutral right     10 right 0.5924563
#> 297        2 accuracy right     10 right 1.3353478
#> 3          3    speed  left      1  left 0.2364465
#> 8          3  neutral  left      1  left 0.2353730
#> 13         3 accuracy  left      1  left 0.3414085
#> 18         3    speed right      1  left 0.3546309
#> 23         3  neutral right      1 right 0.3986662
#> 28         3 accuracy right      1 right 0.2876299
#> 33         3    speed  left      2  left 0.2279650
#> 38         3  neutral  left      2  left 0.1717977
#> 43         3 accuracy  left      2  left 1.0641000
#> 48         3    speed right      2 right 0.2598274
#> 53         3  neutral right      2 right 0.6755983
#> 58         3 accuracy right      2 right 0.3578853
#> 63         3    speed  left      3 right 0.1655877
#> 68         3  neutral  left      3  left 0.4589343
#> 73         3 accuracy  left      3  left 0.2077049
#> 78         3    speed right      3  left 0.1556091
#> 83         3  neutral right      3  left 0.5426318
#> 88         3 accuracy right      3 right 0.4356327
#> 93         3    speed  left      4 right 0.1654606
#> 98         3  neutral  left      4  left 0.9969207
#> 103        3 accuracy  left      4  left 0.7299234
#> 108        3    speed right      4 right 0.4450955
#> 113        3  neutral right      4 right 0.2814783
#> 118        3 accuracy right      4 right 0.6389698
#> 123        3    speed  left      5 right 0.2457152
#> 128        3  neutral  left      5  left 0.5139492
#> 133        3 accuracy  left      5  left 0.5814591
#> 138        3    speed right      5 right 0.1725248
#> 143        3  neutral right      5 right 0.4019443
#> 148        3 accuracy right      5 right 0.5736816
#> 153        3    speed  left      6 right 0.4318007
#> 158        3  neutral  left      6  left 0.2340778
#> 163        3 accuracy  left      6  left 1.1083073
#> 168        3    speed right      6 right 0.2193557
#> 173        3  neutral right      6 right 0.7438618
#> 178        3 accuracy right      6 right 0.2010323
#> 183        3    speed  left      7 right 0.1833217
#> 188        3  neutral  left      7  left 0.8498258
#> 193        3 accuracy  left      7  left 0.2667243
#> 198        3    speed right      7 right 0.1679766
#> 203        3  neutral right      7 right 0.3194990
#> 208        3 accuracy right      7 right 0.4041280
#> 213        3    speed  left      8  left 0.1409040
#> 218        3  neutral  left      8  left 0.2723462
#> 223        3 accuracy  left      8  left 0.6263929
#> 228        3    speed right      8 right 0.2188620
#> 233        3  neutral right      8 right 0.4334330
#> 238        3 accuracy right      8 right 0.3754420
#> 243        3    speed  left      9  left 0.2452776
#> 248        3  neutral  left      9  left 0.2584728
#> 253        3 accuracy  left      9  left 0.4406785
#> 258        3    speed right      9 right 0.2848348
#> 263        3  neutral right      9 right 0.4366882
#> 268        3 accuracy right      9 right 0.2865983
#> 273        3    speed  left     10  left 0.2937653
#> 278        3  neutral  left     10  left 0.3055828
#> 283        3 accuracy  left     10  left 0.4916850
#> 288        3    speed right     10  left 0.2399585
#> 293        3  neutral right     10 right 0.2065790
#> 298        3 accuracy right     10  left 0.4042073
#> 4          4    speed  left      1  left 0.5015753
#> 9          4  neutral  left      1  left 2.0389899
#> 14         4 accuracy  left      1 right 0.3159794
#> 19         4    speed right      1 right 0.3445574
#> 24         4  neutral right      1 right 0.3355026
#> 29         4 accuracy right      1 right 1.5797375
#> 34         4    speed  left      2  left 0.3808129
#> 39         4  neutral  left      2  left 1.8297493
#> 44         4 accuracy  left      2  left 0.6381267
#> 49         4    speed right      2 right 0.3158093
#> 54         4  neutral right      2 right 0.7277419
#> 59         4 accuracy right      2 right 0.5292479
#> 64         4    speed  left      3 right 0.3448164
#> 69         4  neutral  left      3  left 1.3744491
#> 74         4 accuracy  left      3  left 0.6276398
#> 79         4    speed right      3 right 0.8454433
#> 84         4  neutral right      3 right 0.5328646
#> 89         4 accuracy right      3 right 1.3968499
#> 94         4    speed  left      4 right 0.3047267
#> 99         4  neutral  left      4 right 0.9067365
#> 104        4 accuracy  left      4  left 0.7019027
#> 109        4    speed right      4 right 0.3425376
#> 114        4  neutral right      4 right 0.6293099
#> 119        4 accuracy right      4 right 0.3607344
#> 124        4    speed  left      5 right 0.3442119
#> 129        4  neutral  left      5  left 2.3720181
#> 134        4 accuracy  left      5 right 0.3203973
#> 139        4    speed right      5 right 0.3550732
#> 144        4  neutral right      5 right 1.0576791
#> 149        4 accuracy right      5 right 1.1799993
#> 154        4    speed  left      6  left 0.4413562
#> 159        4  neutral  left      6  left 0.9784070
#> 164        4 accuracy  left      6 right 0.3085573
#> 169        4    speed right      6 right 0.3286292
#> 174        4  neutral right      6 right 0.3684513
#> 179        4 accuracy right      6 right 0.3352704
#> 184        4    speed  left      7 right 0.3931154
#> 189        4  neutral  left      7  left 1.1163171
#> 194        4 accuracy  left      7  left 0.7874353
#> 199        4    speed right      7 right 0.3070661
#> 204        4  neutral right      7 right 1.1570909
#> 209        4 accuracy right      7 right 0.3776433
#> 214        4    speed  left      8  left 1.1583415
#> 219        4  neutral  left      8  left 1.1369660
#> 224        4 accuracy  left      8  left 1.5069033
#> 229        4    speed right      8 right 0.4790159
#> 234        4  neutral right      8 right 0.4010402
#> 239        4 accuracy right      8 right 0.3597322
#> 244        4    speed  left      9  left 0.4950517
#> 249        4  neutral  left      9  left 2.0174763
#> 254        4 accuracy  left      9  left 0.6220561
#> 259        4    speed right      9 right 0.4056108
#> 264        4  neutral right      9 right 1.9027530
#> 269        4 accuracy right      9 right 0.6982177
#> 274        4    speed  left     10  left 0.3836568
#> 279        4  neutral  left     10  left 1.2326443
#> 284        4 accuracy  left     10  left 1.1309284
#> 289        4    speed right     10 right 0.3509148
#> 294        4  neutral right     10 right 0.9917207
#> 299        4 accuracy right     10 right 1.3636058
#> 5          5    speed  left      1  left 0.5882340
#> 10         5  neutral  left      1  left 0.9482927
#> 15         5 accuracy  left      1  left 0.9968045
#> 20         5    speed right      1 right 0.5509412
#> 25         5  neutral right      1 right 0.8988565
#> 30         5 accuracy right      1 right 0.7347184
#> 35         5    speed  left      2  left 0.3287062
#> 40         5  neutral  left      2  left 0.6605287
#> 45         5 accuracy  left      2  left 2.3552992
#> 50         5    speed right      2 right 0.5517971
#> 55         5  neutral right      2 right 1.2276347
#> 60         5 accuracy right      2 right 0.6760796
#> 65         5    speed  left      3 right 0.5525209
#> 70         5  neutral  left      3  left 1.0653492
#> 75         5 accuracy  left      3  left 0.5790541
#> 80         5    speed right      3 right 0.8042443
#> 85         5  neutral right      3 right 1.4016122
#> 90         5 accuracy right      3  left 0.3590838
#> 95         5    speed  left      4  left 0.3561858
#> 100        5  neutral  left      4  left 1.9637959
#> 105        5 accuracy  left      4  left 2.1253953
#> 110        5    speed right      4 right 0.5003907
#> 115        5  neutral right      4 right 0.5775180
#> 120        5 accuracy right      4 right 1.4191781
#> 125        5    speed  left      5  left 0.4220682
#> 130        5  neutral  left      5  left 1.6043147
#> 135        5 accuracy  left      5  left 0.7048039
#> 140        5    speed right      5 right 0.7146692
#> 145        5  neutral right      5 right 1.0781700
#> 150        5 accuracy right      5 right 0.9988236
#> 155        5    speed  left      6  left 0.3865632
#> 160        5  neutral  left      6  left 0.3792731
#> 165        5 accuracy  left      6  left 1.1460115
#> 170        5    speed right      6 right 0.7642872
#> 175        5  neutral right      6 right 0.9829130
#> 180        5 accuracy right      6 right 1.0110473
#> 185        5    speed  left      7  left 0.6853513
#> 190        5  neutral  left      7  left 0.6032076
#> 195        5 accuracy  left      7  left 0.4080187
#> 200        5    speed right      7 right 0.4256948
#> 205        5  neutral right      7 right 1.0713036
#> 210        5 accuracy right      7 right 0.9744742
#> 215        5    speed  left      8  left 0.5800564
#> 220        5  neutral  left      8  left 1.7062603
#> 225        5 accuracy  left      8  left 0.5313840
#> 230        5    speed right      8 right 1.0522381
#> 235        5  neutral right      8 right 0.9328861
#> 240        5 accuracy right      8 right 1.5863403
#> 245        5    speed  left      9 right 0.7590235
#> 250        5  neutral  left      9  left 0.7482810
#> 255        5 accuracy  left      9  left 1.1871706
#> 260        5    speed right      9  left 0.5461100
#> 265        5  neutral right      9 right 2.3092375
#> 270        5 accuracy right      9 right 1.2031467
#> 275        5    speed  left     10 right 0.6554156
#> 280        5  neutral  left     10  left 0.8589199
#> 285        5 accuracy  left     10  left 0.5640064
#> 290        5    speed right     10 right 0.6077505
#> 295        5  neutral right     10 right 1.1756832
#> 300        5 accuracy right     10  left 0.4204746