with weights = 'equal', mne.combine_evoked computes sum, not mean
See original GitHub issueFollowing up on a strange variation in the scale of my evokeds, I realized that mne.combine_evoked computes the sum, rather than the mean when weights = ‘equal’ (mne version: ‘0.21.dev0’):
evoked.py, line 876:
naves = np.array([evk.nave for evk in all_evoked], float)
if isinstance(weights, str):
_check_option('weights', weights, ['nave', 'equal'])
if weights == 'nave':
weights = naves / naves.sum()
else:
weights = np.ones_like(naves)
else:
weights = np.array(weights, float)
Shouldn’t it be
weights = np.ones_like(naves) / len(all_evoked)
instead of
weights = np.ones_like(naves)
?
The documentation says
The weights to apply to the data of each evoked instance. Can also be ‘nave’ to weight according to evoked.nave, or “equal” to use equal weighting (each weighted as 1/N).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top Results From Across the Web
mne.combine_evoked — MNE 1.3.dev0 documentation
Merge evoked data by weighted addition or subtraction. Each Evoked in all_evoked should have the same channels and the same time instants.
Read more >The Evoked data structure: evoked/averaged data
For this reason, combining :class: ~mne.Evoked objects with either weights='equal' or by providing custom numeric weights should usually not be done if you ......
Read more >Averaging ERPs: Creating MNE Evoked objects
Since averaging across trials is typically the end goal of an ERP experiment, MNE has a distinct class, Evoked , for ERP data...
Read more >A Reproducible MEG/EEG Group Study With the MNE Software
While the unprocessed data do not show a clear evoked response, ... MNE computes the PSD of raw data using the standard Welch's...
Read more >Evoked - Mainak Jas
In MNE the evoked objects are usually created by averaging epochs data with mne. ... Applying baseline correction (mode: mean) Read a total...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it seems to me like the definitive question here is “what is a more common use case: equally-weighted sum, or equally-weighted average?” Both are possible, it’s a question of which we want to make easy for users with a string argument to
weights
. It is my impression that equally-weighted average is more common, and is also slightly more difficult for users to implement themselves:Therefore I’m preparing a PR to make the code align with the docstring for
weights='equal'
and also to change the docstring’s recommendation about how to do a subtraction, since it will no longer be correct to useweights='equal'
for subtraction after that change.There is definitely something wrong here. If I recall correctly the discussion among myself, @jasmainak, @jona-sassenhagen, and @agramfort, it was decided that
weights='equal'
should work the way it does in order for subtractions of evokeds to work sensibly. I think between that concern and trying hard to get thenave
computation correct, we lost sight of the common use case where users want1/N
weighting. For a quick work-around you could pass an array of1/N
values as weights, but thennave
will be wrong. I think it’s time to re-think this implementation so that the most common use cases are correct, obvious, and hard to mess up.