n_subj =40n_item =3# things are expressed as "between", so "within subjects" is "between items"item_btwn =Dict(:frequency => ["high", "medium", "low"])design =simdat_crossed(MersenneTwister(42), n_subj, n_item; item_btwn = item_btwn)design =DataFrame(design)
120×4 DataFrame
95 rows omitted
Row
subj
item
frequency
dv
String
String
String
Float64
1
S01
I1
high
-0.556027
2
S02
I1
high
-0.444383
3
S03
I1
high
0.0271553
4
S04
I1
high
-0.299484
5
S05
I1
high
1.77786
6
S06
I1
high
-1.1449
7
S07
I1
high
-0.468606
8
S08
I1
high
0.156143
9
S09
I1
high
-2.64199
10
S10
I1
high
1.00331
11
S11
I1
high
1.08238
12
S12
I1
high
0.187028
13
S13
I1
high
0.518149
⋮
⋮
⋮
⋮
⋮
109
S29
I3
low
-0.338763
110
S30
I3
low
-0.0953675
111
S31
I3
low
0.768972
112
S32
I3
low
1.44244
113
S33
I3
low
-0.275032
114
S34
I3
low
-0.379637
115
S35
I3
low
-0.722696
116
S36
I3
low
0.139661
117
S37
I3
low
-1.40934
118
S38
I3
low
1.05546
119
S39
I3
low
-2.23782
120
S40
I3
low
1.15915
Code
unique!(select(design, :item, :frequency))
3×2 DataFrame
Row
item
frequency
String
String
1
I1
high
2
I2
medium
3
I3
low
Code
m0 =let contrasts, form contrasts =Dict(:frequency =>HelmertCoding(base="high")) form =@formula(dv ~1+ frequency + (1+ frequency | subj))fit(MixedModel, form, design; contrasts)end
design_partial =filter(design) do row subj =parse(Int, row.subj[2:end]) item =parse(Int, row.item[2:end])# for even-numbered subjects, we keep all conditions# for odd-numbered subjects, we keep only the two "odd" items,# i.e. the first and last conditionsreturniseven(subj) ||isodd(item)endsort!(unique!(select(design_partial, :subj, :frequency)), :subj)
100×2 DataFrame
75 rows omitted
Row
subj
frequency
String
String
1
S01
high
2
S01
low
3
S02
high
4
S02
medium
5
S02
low
6
S03
high
7
S03
low
8
S04
high
9
S04
medium
10
S04
low
11
S05
high
12
S05
low
13
S06
high
⋮
⋮
⋮
89
S36
medium
90
S36
low
91
S37
high
92
S37
low
93
S38
high
94
S38
medium
95
S38
low
96
S39
high
97
S39
low
98
S40
high
99
S40
medium
100
S40
low
Code
m1 =let contrasts, form contrasts =Dict(:frequency =>HelmertCoding(base="high")) form =@formula(dv ~1+ frequency + (1+ frequency | subj))fit(MixedModel, form, design_partial; contrasts)end