Issue with TRF Curve
I would like to inquire why my constructed encoding model shows reasonable accuracy, but the TRF (temporal response function) curve appears peculiar. I followed the CNPSP tutorial to write my own TRF code, and the specific approach and code are as follows:
1. MEG Preprocessing
1.1. Alignment of MEG misc channels and audio using cross-correlation.
1.2. Applying a 60Hz notch filter, 15Hz low-pass filter, and 1Hz high-pass filter to MEG data.
1.3. Downsampling to 100Hz.
1.4. Selecting relevant MEG channels.
1.5. Z-score normalization.
% Notch filter
cfg.bsfilter = 'yes';
cfg.bsfreq = [59 61];
mat_fq = ft_preprocessing(cfg, mat);
% Low-pass and high-pass filter
cfg.lpfilter = 'yes';
cfg.lpfreq = 15;
cfg.hpfilter = 'yes';
cfg.hpfreq = 1;
% Resample
cfg = [];
cfg.resamplefs = 100;
cfg.sampleindex = 'no';
mat_rs = ft_resampledata(cfg, mat_fq);
cfg = [];
cfg.channel = {'MEG*1','MEG*2','MEG*3'};
data_orig = ft_selectdata(cfg, mat_rs);
eeg{1,s} = data_orig.trial{1, 1};
cell_mean = mean(data{i}(:));
cell_std = std(data{i}(:));
normalized_data{i} = (data{i} - cell_mean) / cell_std;
TRF Training
For each subject, the following steps are performed:
- Alignment of MEG and features.
- Leave-one-out training and testing with 8 stories.
% Ensure the data is of the same length
for t = 1:8
eegLen = length(eeg{1, t});
stimLen = length(stim{1, t});
minLen = min(eegLen, stimLen);
eeg{1, t} = eeg{1, t}(1:minLen, :);
stim{1, t} = stim{1, t}(1:minLen, :);
end
fs = 100;
Dir = 1;
tmin = 0;
tmax = 500;
lambda_idx = -5:1:5;
lambda_vals = 10.^lambda_idx;
nlambda = numel(lambda_vals);
for x = 1:8
% Define training and test sets
story = x;
stim_train = stim;
eeg_train = eeg;
stim_train(:, story) = [];
eeg_train(:, story) = [];
stim_test = stim(:, story);
eeg_test = eeg(:, story);
% Run fast cross-validation
cv = mTRFcrossval(stim_train, eeg_train, fs, Dir, tmin, tmax, lambda_vals, 'zeropad', 0, 'fast', 0);
% Model training
% Get optimal lambda
[~, idx] = max(mean(cv.r, [1 3]));
lambda = lambda_vals(idx);
% Train model
model = mTRFtrain(stim_train, eeg_train, fs, Dir, tmin, tmax, lambda, 'zeropad', 0);
pathmodel = strcat('sub', num2str(all(z)), 'story', num2str(x), '_train_model.mat');
save(pathmodel, 'model', '-V6');
clear cv
% Model testing
% Test model
[~, test] = mTRFpredict(stim_test, eeg_test, model, 'zeropad', 0);
pathtest = strcat('sub', num2str(all(z)), 'story', num2str(x), '_test_cr.mat');
save(pathtest, 'test', '-V6');
clear stim_train eeg_train pred test
end
The average accuracy of the encoding model is 0.05, which is above random chance levels. However, my TRF results, especially the TRF curve for envelope features extracted using mTRFenvelope
, appear unusual. Even though I extracted other features like pitch, spectrograms, and word onsets, and their accuracies fall within the expected range, none of the TRF model graphs resemble those reported in previous literature; they all appear quite strange.