[Mne_analysis] Grand average in MNE-python

Mads Jensen mje.mads at gmail.com
Wed Feb 12 05:23:40 EST 2014
Search archives:

Hi,

thanks for all the explanations and help. Very useful.

- mads

On 11-02-2014 23:35, Denis-Alexander Engemann wrote:
> On Tue, Feb 11, 2014 at 11:30 PM, Martin Luessi
> <mluessi at nmr.mgh.harvard.edu> wrote:
>> On 02/11/14 17:13, Denis-Alexander Engemann wrote:
>>> Sorry Mads,
>>>
>>> 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
>>
>
> Good to know ;-)
>
>> #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.
>
> just to avoid confusion, the operator overloading is also used when
> using a sum function on a list of evoked objects.
> The manual way would be to directly access `evoked.data`
>
> Best,
> Denis
>
>>
>> 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:
>>>> Hi Mads,
>>>>
>>>> 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,
>>>>> mads
>>>>> _______________________________________________
>>>>> 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
>>>>> contains patient information, please contact the Partners Compliance HelpLine at
>>>>> http://www.partners.org/complianceline . If the e-mail was sent to you in error
>>>>> but does not contain patient information, please contact the sender and properly
>>>>> 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
>>
>> Department of Radiology
>> Athinoula A. Martinos Center for Biomedical Imaging
>> Massachusetts General Hospital
>> Harvard Medical School
>> 149 13th Street
>> Charlestown, MA 02129
>>
>> Fax: +1 617 726-7422



More information about the Mne_analysis mailing list