# averaging in MNE

**URL:** <https://mne.discourse.group/t/averaging-in-mne/112>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [April 13, 2009, 2:39pm UTC](https://mne.discourse.group/t/averaging-in-mne/112 "2009-04-13T14:39:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 13, 2009, 2:39pm UTC](https://mne.discourse.group/t/averaging-in-mne/112/1 "2009-04-13T14:39:39Z")

</div>

Hello,

I have a couple questions regarding averaging MEG data with MNE and I  
was wondering if you could help me.

1) Is it possible to average a certain event only if something else  
happened after it? For example, let's say I have conditions 1 and 2. I  
want to average each condition, but only when the trigger happened and  
I received a response from the subject, which is coded as a 3 in the  
trigger line. In other words, average all the occurrences of 1 or 2  
only when there's a 3 after them. I wrote a script to do that in  
Matlab using the MNE toolbox, but since then lots of people have  
joined the lab and they are not very familiar with matlab, so I was  
wondering if there was a way to do such average within MNE, either by  
using the GUI or a combination of .ave and .eve files.

2) Something else my script does is to average conditions across  
different fif files. In the example above, I could have several fif  
files with such events, and the final .fif averaged file would  
represent the averages across all files. I imagine this is possible to  
do with the MNE software by using the global average parameter. Is  
that correct? Is there a different way to do it besides specifying a  
different .ave file for each of my raw .fif files? It's usually not a  
problem to do that for only a couple .fif files, but when there're  
about 10 different .fif files to be averaged, it starts to get a  
little cumbersome to keep track of all the .ave files, which look very  
similar except for the output parameter.

Thanks,

Gustavo

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 14, 2009, 10:44am UTC](https://mne.discourse.group/t/averaging-in-mne/112/2 "2009-04-14T10:44:45Z")

</div>

HI Gustavo,

> Hello,
> 
> I have a couple questions regarding averaging MEG data with MNE and  
> I was wondering if you could help me.
> 
> 1) Is it possible to average a certain event only if something else  
> happened after it? For example, let's say I have conditions 1 and 2.  
> I want to average each condition, but only when the trigger happened  
> and I received a response from the subject, which is coded as a 3 in  
> the trigger line. In other words, average all the occurrences of 1  
> or 2 only when there's a 3 after them. I wrote a script to do that  
> in Matlab using the MNE toolbox, but since then lots of people have  
> joined the lab and they are not very familiar with matlab, so I was  
> wondering if there was a way to do such average within MNE, either  
> by using the GUI or a combination of .ave and .eve files.

Unfortunately, there is no direct way to do conditional averaging in  
mne\_process\_raw/mne\_browse\_raw (yet). However, the easiest way around  
this is to output a text format event file a and manipulate this file  
so that new event numbers are assigned to the events meeting the  
requested combinations. I guess such a script could be even written in  
Excel.

> 2) Something else my script does is to average conditions across  
> different fif files. In the example above, I could have several fif  
> files with such events, and the final .fif averaged file would  
> represent the averages across all files. I imagine this is possible  
> to do with the MNE software by using the global average parameter.  
> Is that correct? Is there a different way to do it besides  
> specifying a different .ave file for each of my raw .fif files? It's  
> usually not a problem to do that for only a couple .fif files, but  
> when there're about 10 different .fif files to be averaged, it  
> starts to get a little cumbersome to keep track of all the .ave  
> files, which look very similar except for the output parameter.

You can, indeed, make a grand average file using mne\_process\_raw. You  
can use the --saveavetag option to create the output file names  
automatically. Also, if mne\_process\_raw runs out of ave file name  
names when processing the raw files, the last one available will be  
used. If you use custom event files, you can specify them on the  
command line (in version 2.6).

Let's assume

my.ave is your averaging file  
my1\_raw.fif and my2\_raw.fif are your raw data files  
my1.eve and my2.eve are your event files

You can do

mne\_process\_raw \<other options\> --raw my1\_raw.fif --raw my2\_raw.fif --  
eve my1.eve --eve my2.eve --ave my.ave --saveavetag -ave --gave my-  
gave.fif

This will produce the averages in my1-ave.fif and my2-ave.fif and log  
files my1-ave.log and my2-ave.log independent of what is specifie in  
my.ave. Also, the my1.eve and my2.eve override the event file  
specification (if any) in my.ave.

Similarly, the --savecovtag option can be used to generate the noise-  
covariance calculation output file names.

I hope this helps.

- Matti

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 14, 2009, 4:04pm UTC](https://mne.discourse.group/t/averaging-in-mne/112/3 "2009-04-14T16:04:31Z")

</div>

Matti,

That worked great. Thanks!

Best,

Gus

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 15, 2009, 4:51pm UTC](https://mne.discourse.group/t/averaging-in-mne/112/4 "2009-04-15T16:51:00Z")

</div>

Dear all,

I have a question about conversion of fif file into mat file;. I would like to convert my raw data (fif file) into matlab file. For this, I tried to use the function mne\_convert\_mne\_data but I have a message "no evoked data here". I have the same message if I try this with averaged data (fif file) directly obtained by on-line averaging.

I exactly wrote this command line:

mne\_convert\_mne\_data -meas my filename.fif -mat -out my filename.mat

Something is wrong ?

Thanks for your help !

Bye

Etienne LABYT

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 15, 2009, 6:34pm UTC](https://mne.discourse.group/t/averaging-in-mne/112/5 "2009-04-15T18:34:24Z")

</div>

Dear Etienne,

Here are some relevant points:

1. mne\_convert\_mne\_data does not convert raw data files (mne\_raw2mat  
does this).

2. Were your data collected with MaxShield on? If so, I think even the  
averages need to be passed through maxfilter before they can be  
processed further (not absolutely sure about this).

3. The MNE Matlab toolbox pretty much makes mne\_convert\_mne\_data and  
mne\_raw2mat obsolete. The fif files can be now read directly from  
Matlab without having to waste disk space for the converted data.

- Matti
