Linear Model with Overlap Correction
We recommend you briefly go over the mass-univariate linear modelling tutorial
In this notebook we will fit regression models to (simulated) EEG data. We will see that we need some type of overlap correction, as the events are close in time to each other, so that the respective brain responses overlap. If you want more detailed introduction to this topic check out our paper.
Setting up & loading the data
using Unfold
using UnfoldSim
using UnfoldMakie,CairoMakie
using DataFrames
data, evts = UnfoldSim.predef_eeg()
Overlap Correction
For an overlap correction analysis we will do one additional step: define a temporal basisfunction. The steps are as following:
- specify a temporal basisfunction
- specify a formula
- fit a linear model for each channel (one for all timepoints!)
- visualize the results.
Timeexpanded / Deconvolved ModelFit
1. specify a temporal basisfunction
By default, we would want to use a FIR basisfunction. See Basis Functions for more details.
basisfunction = firbasis(τ=(-0.4,.8),sfreq=100)
2. specify a formula
We specify the same formula as before
f = @formula 0~1+condition+continuous
3. fit the linear model
The formula and basisfunction is not enough on their own. We also need to specify which event and which formula matches - this is important in cases where there are multiple events with different formulas
bf_vec = [Any=>(f,basisfunction)]
The Any
means to use all rows in evts
. In case you have multiple events, you'd want to specify multiple basisfunctions e.g. bfDict = ["stimulus"=>(f1,basisfunction1), "response"=>(f2,basisfunction2)]
You likely have to specify a further argument to fit
: eventcolumn="type"
with type
being the column in evts
that codes for the event (stimulus / response in this case)
Now we are ready to fit a UnfoldLinearModel
. Not that instead of times
as in the mass-univariate case, we have to provide the BasisFunction
type now.
m = fit(UnfoldModel,bf_vec,evts,data);
4. Visualize the model
Similarly to the previous tutorial, we can visualize the model
results = coeftable(m)
plot_erp(results)

Cool! All overlapping activity has been removed and we recovered the simulated underlying signal.