FIR-Scaled duration predictors
using Unfold
using Interpolations
using UnfoldSim
using UnfoldMakie, CairoMakie
using DataFrames
data, evts = UnfoldSim.predef_eeg(sfreq = 10, n_repeats = 1)
evts.duration = 5:245:24putting scale_duration = Interpolation.Linear() will introduce a Cameron-Hassall 2022 PNAS- Style basisfunction, that scales with the :duration column
basisfunction = firbasis(ฯ = (-1, 2), sfreq = 5, scale_duration = Interpolations.Linear())โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ8ร16 SparseArrays.SparseMatrixCSC with 16 stored entries:
โ ::BasisFunction โโกโ โ โ คโฃโ โ โ โ โค
โ name: โโฃโ โ โ โ โ โ โ คโฃโฆ
โ kerneltype: FIRBasis โ
โ width: 16 โ
โ height: 0 โ
โ colnames: [-1.0, -0.8 ... 2.0] โ
โ times: [-1.0, -0.8 ... 2.0] โ
โ collabel: time โ
โ shift_onset: -5 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Two examples with duration = 10
Unfold.kernel(basisfunction, [0, 10])10ร16 SparseArrays.SparseMatrixCSC{Float64, Int64} with 20 stored entries:
โกโ โ ขโขโกโ โ โ โ โค
โขโ โ โ โ โ ฒโขโกโ โฅ
โฃโ โ โ โ โ โ โ โ โฆand duration = 20
Unfold.kernel(basisfunction, [0, 20])20ร16 SparseArrays.SparseMatrixCSC{Float64, Int64} with 38 stored entries:
โกโ ณโฃโ โ โ โ โ โ โค
โขโ โ โขงโกโ โ โ โ โฅ
โขโ โ โ โ นโฃโ โ โ โฅ
โขโ โ โ โ โ โขณโกโ โฅ
โฃโ โ โ โ โ โ โ โขฆโฆlet's fit a model
f = @formula 0 ~ 1 + condition
bf_vec = [Any => (f, basisfunction)]
m = fit(UnfoldModel, bf_vec, evts, data; eventfields = [:latency, :duration]);
# currently bugged for small matrices
# plot_designmatrix(designmatrix(m))
# thus using
heatmap(Matrix(modelmatrix(m))')
As one can see, the designmatrix is nicely scaled
We can predict overlap-corrected results
p = predict(m; overlap = false)[1]
heatmap(p[1, :, :])
note the missings which are displayed as white pixels.
Block-design predictors
In contrast, it is also possible to put scale_duration = true - which wil not scale the matrix as before, but introduce a step-function.
putting scale_duration = Interpolation.Linear() will introduce a Cameron-Hassall 2022 PNAS- Style basisfunction, that scales with the :duration column
basisfunction = firbasis(ฯ = (-1, 2), sfreq = 5, scale_duration = true)โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ23ร16 SparseArrays.SparseMatrixCSC with 128 stored entries:
โ ::BasisFunction โโกโฃทโฃโ โ โ โ โ โ โค
โ name: โโขโฃฟโฃฟโฃทโฃโ โ โ โ โฅ
โ kerneltype: FIRBasis โโขโ โ ปโฃฟโฃฟโฃทโฃโ โ โฅ
โ width: 16 โโขโ โ โ โ ปโฃฟโฃฟโฃทโฃโฅ
โ height: 16 โโขโ โ โ โ โ โ ปโฃฟโฃฟโฅ
โ colnames: [-1.0, -0.8 ... 2.0] โโฃโ โ โ โ โ โ โ โ ปโฆ
โ times: [-1.0, -0.8 ... 2.0] โ
โ collabel: time โ
โ shift_onset: -5 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Two examples with duration = 10
Unfold.kernel(basisfunction, [0, 10])25ร16 SparseArrays.SparseMatrixCSC{Int64, Int64} with 160 stored entries:
โกโฃทโฃโ โ โ โ โ โ โค
โขโฃฟโฃฟโฃทโฃโ โ โ โ โฅ
โขโ ปโฃฟโฃฟโฃฟโฃทโฃโ โ โฅ
โขโ โ โ ปโฃฟโฃฟโฃฟโฃทโฃโฅ
โขโ โ โ โ โ ปโฃฟโฃฟโฃฟโฅ
โขโ โ โ โ โ โ โ ปโฃฟโฅ
โฃโ โ โ โ โ โ โ โ โฆand duration = 20
Unfold.kernel(basisfunction, [0, 20])35ร16 SparseArrays.SparseMatrixCSC{Int64, Int64} with 320 stored entries:
โกโฃทโฃโ โ โ โ โ โ โค
โขโฃฟโฃฟโฃทโฃโ โ โ โ โฅ
โขโฃฟโฃฟโฃฟโฃฟโฃทโฃโ โ โฅ
โขโฃฟโฃฟโฃฟโฃฟโฃฟโฃฟโฃทโฃโฅ
โขโฃฟโฃฟโฃฟโฃฟโฃฟโฃฟโฃฟโฃฟโฅ
โขโ โ ปโฃฟโฃฟโฃฟโฃฟโฃฟโฃฟโฅ
โขโ โ โ โ ปโฃฟโฃฟโฃฟโฃฟโฅ
โขโ โ โ โ โ โ ปโฃฟโฃฟโฅ
โฃโ โ โ โ โ โ โ โ ปโฆlet's fit a model
f = @formula 0 ~ 1 + condition
bf_vec = [Any => (f, basisfunction)]
m = fit(UnfoldModel, bf_vec, evts, data; eventfields = [:latency, :duration]);
heatmap(Matrix(modelmatrix(m))')
as one can see, now the designmatrix is not stretched - but rather "block"-ed
p = predict(m; overlap = false)[1]
heatmap(p[1, :, :])
This page was generated using Literate.jl.