# [Mne_analysis] Grand average in MNE-python

Martin Luessi mluessi at nmr.mgh.harvard.edu
Tue Feb 11 17:30:21 EST 2014
 Previous message: [Mne_analysis] Grand average in MNE-python Next message: [Mne_analysis] Grand average in MNE-python Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Search archives:

```On 02/11/14 17:13, Denis-Alexander Engemann wrote:
>
> too fast, it only works with np.sum or sum from the standardlib.
>
> In [7]: np.sum([evoked, evoked]).nave
> Out[7]: 104
>
> You might then want to divide by .nave

Dividing by nave isn't necessary, the Evoked class takes care of
appropriate scaling. I.e., if you have

#print evoked1.nave
60
#print evoked2.nave
55

#evoked3 = evoked1 + evoked2  # same as using np.sum in Denis' example
#print evoked3.nave
115

The data in evoked3 is the same if the evoked response had been
calculated over 115 trials from one Epochs object. For SourceEstimates,
the number of averages isn't considered, i.e., if you use

stc3 = stc1 + stc2

The stc3.data is simply "stc1.data + stc2.data". So, you will need to
divide the stc yourself, i.e., use

stc3 = (stc1 + stc2) / 2.

The nice thing about using these overloaded operators is that you will
get an error if you try to combine objects which are not compatible,
e.g., evoked responses with different time intervals, source estimates
with different vertices etc.

I hope this helps.

Martin

PS: In case you are curious, the magic for combining evoked responses
happens in the function "merge_evoked" in mne/fiff/evoked.py

> Denis
>
>
>
> On Tue, Feb 11, 2014 at 11:08 PM, Denis-Alexander Engemann
> <denis.engemann at gmail.com> wrote:
>>
>> with stc objects and evoked objects in Python you can use numpy
>> functions to accumulate.
>>
>> grand_ave = np.mean([evoked1, evoked2, evoked3])
>>
>> which will produce another evoked.
>>
>> The same works for stcs.
>>
>>
>> HTH,
>> Denis
>>
>> On Tue, Feb 11, 2014 at 11:01 PM, Mads Jensen <mje.mads at gmail.com> wrote:
>>> Hi MNE community,
>>>
>>> Is there a way to make a grand average of evoked files, and of source
>>> estimations in MNE-python?
>>>
>>> best,
>>> _______________________________________________
>>> Mne_analysis mailing list
>>> Mne_analysis at nmr.mgh.harvard.edu
>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>>
>>>
>>> The information in this e-mail is intended only for the person to whom it is
>>> addressed. If you believe this e-mail was sent to you in error and the e-mail
>>> http://www.partners.org/complianceline . If the e-mail was sent to you in error
>>> dispose of the e-mail.
>>>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>

--
Martin Luessi, Ph.D.

Research Fellow