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}:
11.732 2.011 8.27136 12.9382 … 18.2505 5.76112 3.80815
8.3166 0.806713 6.76657 1.93457 13.4839 14.1415 3.03624
9.44381 20.1224 9.45056 13.7623 9.90079 1.95151 5.6487
12.6111 13.0039 5.7141 7.23329 6.89251 4.5546 7.14017
7.7737 16.284 17.138 13.4378 15.2999 9.28728 3.3846
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.