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×120198 Matrix{Float64}:
 10.5108    0.416251  17.0277   14.8866   …   9.5131    7.66268   5.75951
  2.91731  15.7109     3.70389  16.0292      13.2554   10.2967   15.7648
 18.769    16.2931    11.1187    3.31247     14.9474    9.53028  15.7754
  3.6189   16.6635    11.5203    4.30642     13.0098   11.2412   12.1376
 13.0616    6.30699    2.30865  12.1063       6.78738  13.6806    3.93663

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))
Example block output

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))
Example block output

Voila, the model classified the correct period.


This page was generated using Literate.jl.