using UnfoldDecode
using UnfoldSim
using UnfoldMakie
using CairoMakie
using Unfold
Overlap-corrected decoding tutorial
This approach follows the work of the Deoulle Group, especially Gal Vishne's work as published 2023: https://doi.org/10.1101/2023.06.28.546397
Simulation
We start with simulating some continuous, overlapping data with two conditions. As of now, UnfoldSim
doesnt support multichannel, so we simply repeat the channel and add some noise`
dat, evt = UnfoldSim.predef_eeg()
dat = repeat(dat', 5)
dat .= dat .+ 20 .* rand(size(dat)...)
5×120199 Matrix{Float64}:
4.47017 4.14245 2.84318 3.5998 … 10.1947 1.6747 10.6637
19.3169 17.2812 20.3574 13.0755 13.3753 14.8961 1.75375
16.3673 20.0926 4.53176 3.94819 3.58889 2.07 7.6664
2.92952 4.32864 19.346 4.76091 8.54636 18.5658 5.1866
5.8916 12.9058 16.3997 14.4299 13.5615 12.2012 8.2243
Overlap-model Definition
We have to define what model we want to use for overlap correction We decide for a one-basisfunction model, with one one condition and one covariate, from -0.1
to 0.5
seconds afte the stimulus onset. Sampling rate 100
as in the simulation
des = [Any => (@formula(0 ~ 1 + condition + continuous), firbasis((-0.1, 1.0), 100))];
Fitting and visualizing a single channel of the model
uf = Unfold.fit(UnfoldModel, des, evt, dat[1, :]);
plot_erp(coeftable(uf))

Fitting the Overlap-corrected LDA model
Following the MLJ Modelzoo we have to do the following to load an LDA model
using MLJ, MultivariateStats, MLJMultivariateStatsInterface
LDA = @load LDA pkg = MultivariateStats
uf_lda =
Unfold.fit(UnfoldDecodingModel, des, evt, dat, LDA(), Any => :condition; nfolds = 2) # 2 folds to speed up computation
plot_erp(coeftable(uf_lda); mapping = (; color = :coefname))
Voila, the model classified the correct period.
This page was generated using Literate.jl.