2424 subj_idx = [parse (Int, split (string (s), ' S' )[2 ]) for s in evts. subject]
2525 evts. latency .+ = size (data, 1 ) .* (subj_idx .- 1 )
2626
27-
27+ evts . C = rand ( StableRNG ( 1 ), [ " a " , " b " , " c " ], size (evts, 1 ))
2828 data = reshape (data, 1 , :)
2929 # append!(data, zeros(1000))
3030 data = vcat (data, data)
6262 )
6363 df = Unfold. coeftable (m_mum)
6464 @test isapprox (
65- df[(df. channel.== 1 ). & (df. coefname.== " A: a_small" ). & (df. time.== 0.0 ), :estimate ],
65+ df[
66+ (df. channel .== 1 ) .& (df. coefname .== " A: a_small" ) .& (df. time .== 0.0 ),
67+ :estimate ,
68+ ],
6669 [- 0.02 , 0.054 ],
6770 atol = 0.01 ,
6871 )
8184 )
8285 df = coeftable (m_mum)
8386 @test isapprox (
84- df[(df. channel.== 1 ). & (df. coefname.== " A: a_small" ). & (df. time.== 0.0 ), :estimate ],
87+ df[
88+ (df. channel .== 1 ) .& (df. coefname .== " A: a_small" ) .& (df. time .== 0.0 ),
89+ :estimate ,
90+ ],
8591 [0.031 , 0.05 ],
8692 atol = 0.1 ,
8793 )
101107 )
102108 df = coeftable (m_tum)
103109 @test isapprox (
104- df[(df. channel.== 1 ). & (df. coefname.== " A: a_small" ). & (df. time.== 0.0 ), :estimate ],
110+ df[
111+ (df. channel .== 1 ) .& (df. coefname .== " A: a_small" ) .& (df. time .== 0.0 ),
112+ :estimate ,
113+ ],
105114 [- 0.03 , 0.064 ],
106115 atol = 0.1 ,
107116 )
@@ -120,13 +129,12 @@ end
120129
121130
122131 evts. subjectB = evts. subject
123- evts1 = evts[evts. A.== " a_small" , :]
124- evts2 = evts[evts. A.== " a_big" , :]
132+ evts1 = evts[evts. A .== " a_small" , :]
133+ evts2 = evts[evts. A .== " a_big" , :]
125134
126- f0_lmm = @formula 0 ~ 1 + B + (1 | subject) + (1 | subjectB)
127- @time m_tum = coeftable (
128- fit (UnfoldModel, f0_lmm, evts, data, basisfunction; show_progress = false ),
129- )
135+ f0_lmm = @formula 0 ~ 1 + B + (1 | subject) + (1 + C | subjectB)
136+ @time m = fit (UnfoldModel, f0_lmm, evts, data, basisfunction; show_progress = false )
137+ @time m_tum = coeftable (m)
130138
131139
132140 f1_lmm = @formula 0 ~ 1 + B + (1 | subject)
147155 df = coeftable (r)
148156
149157 @test isapprox (
150- df[(df. channel.== 1 ). & (df. coefname.== " B: b_tiny" ). & (df. time.== 0.0 ), :estimate ],
158+ df[
159+ (df. channel .== 1 ) .& (df. coefname .== " B: b_tiny" ) .& (df. time .== 0.0 ),
160+ :estimate ,
161+ ],
151162 [0.65 , 0.69 ],
152163 rtol = 0.1 ,
153164 )
163174 ),
164175 )
165176
177+
178+ # ----
179+ # # test #13, 2x3 design
180+
181+ f = @formula 0 ~ 1 + A + C + (1 + A + C | subject)
182+ # f = @formula 0~1 + (1|subject)
183+
184+
185+
186+ # cut the data into epochs
187+ # TODO This ignores subject bounds
188+ data_e, times = Unfold. epoch (data = data, tbl = evts, τ = (- 1.0 , 1.9 ), sfreq = 10 )
189+ data_missing_e, times =
190+ Unfold. epoch (data = data_missing, tbl = evts, τ = (- 1.0 , 1.9 ), sfreq = 10 )
191+ evts_e, data_e = Unfold. drop_missing_epochs (copy (evts), data_e)
192+ evts_missing_e, data_missing_e = Unfold. drop_missing_epochs (copy (evts), data_missing_e)
193+
194+ # #####################
195+ # # Mass Univariate Mixed
196+ @time m_mum = fit (
197+ UnfoldModel,
198+ f,
199+ evts_e,
200+ data_e,
201+ times,
202+ contrasts = Dict (:A => EffectsCoding (), :B => EffectsCoding ()),
203+ show_progress = false ,
204+ )
205+ df = Unfold. coeftable (m_mum)
166206end
167207# # Condense check for multi channel, multi
168208@testset " LMM multi channel, multi basisfunction" begin
198238
199239 @test all (last (.! isnothing .(res. group), 8 ))
200240 @test all (last (res. coefname, 8 ) .== " (Intercept)" )
241+
242+ # test more complex formulas
243+ fA0 = @formula (0 ~ 1 + zerocorr (1 + C | subject))
244+ fA1 = @formula (0 ~ 1 + B + C + zerocorr (1 + C | subject2))
245+ evts. C = rand (StableRNG (1 ), [" a" , " b" , " c" ], size (evts, 1 ))
246+ m = fit (
247+ UnfoldModel,
248+ [" a_small" => (fA0, bA0), " a_big" => (fA1, bA1)],
249+ evts,
250+ data;
251+ eventcolumn = " A" ,
252+ show_progress = false ,
253+ )
254+
255+ res = coeftable (m)
256+
201257end
202258
203259
@@ -216,17 +272,15 @@ end
216272 [
217273 Any => (
218274 @formula (
219- 0 ~
220- 1 + A + B + zerocorr (1 + B + A | subject) + zerocorr (1 + B | item)
275+ 0 ~ 1 + A + B + zerocorr (1 + B + A | subject) + zerocorr (1 + B | item)
221276 ),
222277 range (0 , 1 , length = size (data, 1 )),
223278 ),
224279 ],
225280 [
226281 Any => (
227282 @formula (
228- 0 ~
229- 1 + A + B + zerocorr (1 + A + B | subject) + zerocorr (1 + B | item)
283+ 0 ~ 1 + A + B + zerocorr (1 + A + B | subject) + zerocorr (1 + B | item)
230284 ),
231285 range (0 , 1 , length = size (data, 1 )),
232286 ),
0 commit comments