[FieldTrip] NaNs in TFR power spectra resulting from partial artifact rejection
Schoffelen, J.M. (Jan Mathijs)
janmathijs.schoffelen at donders.ru.nl
Thu Dec 1 07:37:59 CET 2022
Hi Hans,
On 29 Nov 2022, at 14:17, Hans Revers via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:
Dear FieldTrip community,
My name is Hans Revers. I am a PhD student in the Cognitive Neuropsychology department at Tilburg University, working on decoding emotions from EEG patterns.
I would appreciate your insight on how to handle NaNs in TFR power spectra resulting from partial artifact rejection.
We have trials of 90 seconds duration, with artifacts marked from pre-processing in Brain Vision Analyzer. We wish to do a time-frequency analysis (montecarlo cluster analysis) and a classification (mvpa-light). We would want to exclude only the artefact parts per trial while retaining the non-artifact parts and the temporal information. Partial rejection of artifacts appears to be the way to achieve this (https://mailman.science.ru.nl/pipermail/fieldtrip/2018-May/012138.html).
% reject artefact cfg
cfg_artifact = [];
cfg_artifact.artfctdef.reject = 'partial';
% remove artifacts
cfg_artifact.artfctdef.xxx.artifact = formatArtifactList(Dairy_per_pp(pp_i).cfg);
% The formatArtifactList() function returns an Nx2 matrix containing
% the start/end samples of each ‘Bad Interval’.
ConditionA_per_pp(pp_i) = ft_rejectartifact(cfg_artifact, ConditionA _per_pp(pp_i));
This works as expected. Artifact intervals are stored in the cfg of the data in artfcdef.xxx.artifact. Next, ft_freqanalysis results in NaNs in the power spectrum for these intervals with a half taper width before and after. Baseline normalization with ft_freqbaseline seems to handle these NaNs just fine. So far, so good. (I guess we need to make sure that the baseline does not consist of solely NaNs.)
However, when we average over participants with ft_freqgrandaverage, the GA results in a NaN for each time bin that has a NaN for one (or more) of the participants. We had expected a nanmean result.
This could be easily fixed by calculating our own nanmean GA powerspectrum, but I am hesitant to alter the intended workings of FieldTrip and I have the following concerns:
Question 1) Are there reasons not to use a nanmean GA?
No, there is not reason not to use a nanmean. Particularly, if the average is ‘just’ used for visualization or so. Note that the ft_freqgrandaverage is historically an old beast. I can imagine that it does not deal gracefully with NaNs, if they happen to pop up in different time points for different subjects (which - in itself - I find a bit surprising, because if ft_freqanalysis deals with the NaNs gracefully, I would expect consistency across subjects). As an alternative to ft_freqgrandaverage, you could try a combo call to ft_appendfreq, followed by a call to ft_selectdata (with cfg.avgoverrpt = ‘yes’). Ft_selectdata has functionality to use nanmean, or mean for the averaging.
ft_freqstatistics appears to run unaffected by the presence of NaNs in the per-pp power spectra. We are using non-parametric montecarlo cluster analysis with depsamplesT test. ft_statfun_depsamplesT seems to use a nanmean in the calculation of the statistics.
Question 2) Can we assume that the statistics are reliable? Or do the NaNs compromise the statistics?
I’m not sure what you mean with ‘reliable’, but the inferential procedure (+ its conclusion) will still be valid. I guess that as long as the percentage of NaNs for a given data point is low given the total number of subjects, there may be some more noise on the test statistic for those data points (compared to the data points to which all subjects have contributed).
And similarly
Question 3) Will mvpa classification results be reliable?
Well, I’d say that mvpa classification is done at the first (subject) level, and group level statistics are performed on the performance scores. So this sounds to me as a slightly different issue. I don’t know whether (and how) the mvpa works with missing data (partial artifact rejection).
Best wishes,
Jan-Mathijs
Any help would be appreciated.
Kind regards,
Hans Revers
Department of Cognitive Neuropsychology<https://urldefense.com/v3/__https://www.tilburguniversity.edu/about/schools/socialsciences/organization/departments/cognitive-neuropsychology.htm__;!!HJOPV4FYYWzcc1jazlU!-brl_sNsdOMz0Oj0QzbxpMbDjqgae5VDMPPesqlreMz47FFf2RBY8SMXg_fyY2jCzLSvy2MESGigE9NMDBvLoMD7knjPjBCSgvu0og$>
Tilburg University
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!-brl_sNsdOMz0Oj0QzbxpMbDjqgae5VDMPPesqlreMz47FFf2RBY8SMXg_fyY2jCzLSvy2MESGigE9NMDBvLoMD7knjPjBAhIwf6NQ$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20221201/c66c2698/attachment.htm>
More information about the fieldtrip
mailing list