[FieldTrip] calculating grand mean while ignoring channels with NaN values ("ft_freqgrandaverage")

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Wed Feb 8 11:41:46 CET 2023

Dear Anqi,

I can imagine indeed that (the rather old code of) ft_freqgrandaverage does not deal elegantly with subject-specific missing channel data. Indeed, when I read the code at https://urldefense.com/v3/__https://github.com/fieldtrip/fieldtrip/blob/master/ft_freqgrandaverage.m__;!!HJOPV4FYYWzcc1jazlU!9jLKntTeLg3NY3-97TjouwQfEZrJWMD78ZXV8zQuqrD1V8Sefrz7OcGadGUVnacYJQU7mmPTlnFPkTiW1qkQzjnsv8yb9iLPcld8jg$  there is no mention of a cfg.nanmean option in the help documentation of the function, nor can I find anything relating to nans in the code itself. It is still on the to-do list to replace the function’s code by a more up-to-date functionality, possibly using a sequence of calls to ft_appendfreq (using cfg.appenddim = ‘rpt’), and then a call to ft_selectdata (in case cfg.keepindividual=’no’), with cfg.avgoverrpt = ‘yes’, and using an optional cfg.nanmean = ‘yes’. I don’t have time to work on this myself anytime soon, but would be happy to guide you through the process in making the required changes to the code yourself. The best way to get started would be to create a new issue on the fieldtrip github repository, and then start working towards a mergable pull request in an issue branch of your own forked copy of the fieldtrip repo (https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/development/git/__;!!HJOPV4FYYWzcc1jazlU!9jLKntTeLg3NY3-97TjouwQfEZrJWMD78ZXV8zQuqrD1V8Sefrz7OcGadGUVnacYJQU7mmPTlnFPkTiW1qkQzjnsv8yb9iKSE_JzRA$ ).

Looking forward to push this forward.

Best wishes,

On 6 Feb 2023, at 09:12, Lei, A. (Anqi) via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Dear FieldTrip list,

I have a quick question about using “ft_freqgrandaverage” to calculate a group average of powerspectrum while ignoring missing channels across subjects.

Some subjects in my dataset have bad channels so I dropped these channels and replaced their values with NaNs instead of doing interpolation. However, “ft_freqgrandaverage” doesn’t seem to ignore these NaNs while calculating the grand mean so I ended up with a lot of missing channels in my group average – is there a way for the function to ignore channels with NaNs? (I tried to use cfg.nanmean = 'yes' but it didn’t work).

Thank you!

fieldtrip mailing list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230208/415727e2/attachment.htm>

More information about the fieldtrip mailing list