How to model multiple events

When dealing with overlapping data, it is often necessary to model multiple eventtypes (e.g. fixations, stimuli, responses).

Load Example Data

using Unfold
using UnfoldMakie, CairoMakie
using DataFrames
using StatsModels
using MixedModels

include(joinpath(dirname(pathof(Unfold)), "../test/test_utilities.jl")) # to load data
dat, evts = loadtestdata("test_case_4b");

evts[1:5,:]
5×3 DataFrame
Rowlatencytypeintercept
Int64String7Int64
138eventA1
250eventB1
389eventA1
4102eventB1
5144eventA1

The type column of table evts contains two conditions: eventAandeventB(if your eventstypes are specified in a different column, you need to define the keywordargumenteventcolumnin thefit` command below)

Specify formulas and basisfunctions

bf1 = firbasis(τ = (-0.4, 0.8), sfreq = 50)
bf2 = firbasis(τ = (-0.2, 1.2), sfreq = 50)

For each event, a basis function and formula must be specified. The same basis and formulas may be used.

f  = @formula 0 ~ 1
FormulaTerm Response: 0 Predictors: 1

For each event, we must specify the formula and basis function to be used.

bfDict = [ "eventA" => (f, bf1),
           "eventB" => (f, bf2) ]

Finally, fitting & plotting works the same way as always

m = Unfold.fit(
    UnfoldModel,
    bfDict,
    evts,
    dat,
    solver = (x, y) -> Unfold.solver_default(x, y; stderror = true),
    eventcolumn = "type",
)
results = coeftable(m)
plot_erp(results; stderror = true, mapping = (; col = :eventname))
Example block output