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}:
  1.34885  15.8571    11.9862   18.6993  …   0.232752  11.3234    3.00892
  1.18951  10.2119    17.4676   10.8299      6.0187    14.6244   10.316
 15.5682    0.979053  17.77     12.3471     19.5393     2.63031   3.45336
  9.90111   6.44339    5.70388  18.7839     10.072     16.5842    0.315559
  6.56144  15.4589     6.51715  18.1427      0.800415  11.8198    2.15404

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.