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}:
 19.6978    8.08767  17.5638    10.439    …   2.50607  19.0596     7.92488
  7.74462  11.8711    0.705633   9.7881       2.01985  14.5811    17.9742
 17.6398   10.8858    8.01589   20.4422      12.8524    4.91621    2.81294
 13.6465    5.13836  17.2836     9.74502     17.3885   14.3746     5.55592
 10.8251   19.7006    2.04726   17.3634      15.6874    0.371633   2.65462

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.