# MNE-Python and R compatibility

**URL:** <https://mne.discourse.group/t/mne-python-and-r-compatibility/1912>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 6, 2019, 7:00pm UTC](https://mne.discourse.group/t/mne-python-and-r-compatibility/1912 "2019-08-06T19:00:53Z")\
**Posts on this page:** 4\
**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:** [August 6, 2019, 7:00pm UTC](https://mne.discourse.group/t/mne-python-and-r-compatibility/1912/1 "2019-08-06T19:00:53Z")

</div>

External Email - Use Caution

MNE Analysis Team,

Let me first begin by stating what our lab is primarily interested in, and currently doing. We do psychophys studies directly related to startle-blink response and postauricular response. We also work with skin conductance, corrugator, zygomatic (EMG), EOG, ECG, and EEG. Currently, we run Neuroscan, and use the resulting CNT files to do statistical analysis on all study subjects with SPSS and R. We have been in works this summer to complete a script through Jupyter notebooks that will process our raw CNT files into processed FIF files, and this is where the questions begin.

How large can a FIF file be? If a FIF file has a limitation on its size, how do we run statistical analysis on multiple files for the same participant? Furthermore, how do we run analysis on multiple subjects and multiple files? Will a FIF file be compatible with statistical analysis? The real issue that our lab sees is how will be able to create component scores that can be output to other programs for statistical analysis, primarily R. There's a hint about how to do this at the start of the scripts on this page after the from import statements:  
[https://martinos.org/mne/stable/auto\_examples/connectivity/plot\_mne\_inverse\_envelope\_correlation.html#sphx-glr-auto-examples-connectivity-plot-mne-inverse-envelope-correlation-py](https://martinos.org/mne/stable/auto_examples/connectivity/plot_mne_inverse_envelope_correlation.html#sphx-glr-auto-examples-connectivity-plot-mne-inverse-envelope-correlation-py)

However, maybe we require further explanation as we are not interested necessarily in one subject at a time rather ALL subjects at a time.

Thank you in advance for any insight that you may be able to provide on these matters and of course your time.

Best,  
UNLV PEPLab  
Bianca Islas  
Research Assistant  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20190806/384d26d4/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190806/384d26d4/attachment.html)

---

<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:** [August 6, 2019, 7:11pm UTC](https://mne.discourse.group/t/mne-python-and-r-compatibility/1912/2 "2019-08-06T19:11:01Z")

</div>

External Email - Use Caution

Hi Bianca,

Hi Bianca,

Did you have a look at MNE-R? [https://mne.tools/mne-r/index.html](https://mne.tools/mne-r/index.html)  
It is a small library that facilitates calling MNE-Python through R and making data frames from fif-compatible data structures.

For what concerns your question, the fif file is not meant to handle data from multiple subjects.  
You would use other formats for that.  
In Python we usually do things in memory, making big matrices from multiple subjects.  
For getting data for all subjects, you would need to write separate files and combine them in R or make a big data frame.

I hope that helps.  
Denis

---

<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:** [August 6, 2019, 8:46pm UTC](https://mne.discourse.group/t/mne-python-and-r-compatibility/1912/3 "2019-08-06T20:46:00Z")

</div>

External Email - Use Caution

Hi Bianca,  
To expand on Denis's answer a little:

Many MNE-Python objects (Raw, Epochs, Evoked, SourceEstimate) have a  
to\_data\_frame() method that will create a Pandas DataFrame in memory, which  
you can then save to many formats including CSV. From what you've told us,  
that might be an easier way than using FIF as an intermediate format.  
Looping over subjects in Python, you could write a separate CSV for each  
subject and the combine them in R, or you can combine the pandas DataFrames  
within Python before writing one big CSV. Or (as Denis says) you can write  
the loop within R and use MNE-R to do whatever preprocessing steps you  
need, and then in theory you don't even need to write intermediate files  
(though you might want to anyway).  
-- dan

Daniel McCloy  
[http://dan.mccloy.info/](http://dan.mccloy.info/)  
Research Engineer  
Institute for Learning and Brain Sciences  
University of Washington

---

<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:** [August 7, 2019, 5:35am UTC](https://mne.discourse.group/t/mne-python-and-r-compatibility/1912/4 "2019-08-07T05:35:45Z")

</div>

Depending on what you're doing, several of us have little auxiliary  
packages that might help. For e.g. extracting single-trial mean voltage  
within a given time window, I have a utility function in my philistine  
package:

[https://philistine.readthedocs.io/en/latest/api/philistine.mne.retrieve.html#philistine.mne.retrieve](https://philistine.readthedocs.io/en/latest/api/philistine.mne.retrieve.html#philistine.mne.retrieve)

Phillip

> ???External Email - Use Caution???
> 
> Hi Bianca,  
> To expand on Denis's answer a little:
> 
> Many MNE-Python objects (Raw, Epochs, Evoked, SourceEstimate) have a  
> to\_data\_frame() method that will create a Pandas DataFrame in memory,  
> which you can then save to many formats including CSV.? From what you've  
> told us, that might be an easier way than using FIF as an intermediate  
> format. Looping over subjects in Python, you could write a separate CSV  
> for each subject and the combine them in R, or you can combine the  
> pandas DataFrames within Python before writing one big CSV. Or (as Denis  
> says) you can write the loop within R and use MNE-R to do whatever  
> preprocessing steps you need, and then in theory you don't even need to  
> write intermediate files (though you might want to anyway).  
> -- dan
> 
> Daniel McCloy  
> [http://dan.mccloy.info/](http://dan.mccloy.info/)  
> Research Engineer  
> Institute for Learning and Brain Sciences  
> University of Washington
> 
> &nbsp;&nbsp;&nbsp;&nbsp;? ? ? ? External Email - Use Caution? ? ? ?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Hi Bianca,
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Hi Bianca,
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Did you have a look at? MNE-R? [https://mne.tools/mne-r/index.html](https://mne.tools/mne-r/index.html)  
> &nbsp;&nbsp;&nbsp;&nbsp;It is a small library that facilitates calling MNE-Python through R  
> &nbsp;&nbsp;&nbsp;&nbsp;and making data frames from fif-compatible data structures.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;For what concerns your question, the fif file is not meant to handle  
> &nbsp;&nbsp;&nbsp;&nbsp;data from multiple subjects.  
> &nbsp;&nbsp;&nbsp;&nbsp;You would use other formats for that.  
> &nbsp;&nbsp;&nbsp;&nbsp;In Python we usually? do things in memory, making big matrices from  
> &nbsp;&nbsp;&nbsp;&nbsp;multiple subjects.  
> &nbsp;&nbsp;&nbsp;&nbsp;For getting data for all subjects, you would need to write separate  
> &nbsp;&nbsp;&nbsp;&nbsp;files and combine them in R or make a big data frame.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;I? hope that helps.  
> &nbsp;&nbsp;&nbsp;&nbsp;Denis
> 
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\>? ? ? ? ?External Email - Use Caution? ? ? ?  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> MNE Analysis Team,  
> &nbsp;&nbsp;&nbsp;&nbsp;\>?  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Let me first begin by stating what our lab is primarily interested  
> &nbsp;&nbsp;&nbsp;&nbsp;in, and currently doing. We do psychophys studies directly related  
> &nbsp;&nbsp;&nbsp;&nbsp;to startle-blink response and postauricular response.? We also work  
> &nbsp;&nbsp;&nbsp;&nbsp;with skin conductance, corrugator, zygomatic (EMG), EOG, ECG, and  
> &nbsp;&nbsp;&nbsp;&nbsp;EEG.? Currently, we run Neuroscan, and use the resulting CNT files  
> &nbsp;&nbsp;&nbsp;&nbsp;to do statistical analysis on all study subjects with SPSS and R.?  
> &nbsp;&nbsp;&nbsp;&nbsp;We have been in works this summer to complete a script through  
> &nbsp;&nbsp;&nbsp;&nbsp;Jupyter notebooks that will process our raw CNT files into processed  
> &nbsp;&nbsp;&nbsp;&nbsp;FIF files, and this is where the questions begin.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>?  
> &nbsp;&nbsp;&nbsp;&nbsp;\> How large can a FIF file be?? If a FIF file has a limitation on  
> &nbsp;&nbsp;&nbsp;&nbsp;its size, how do we run statistical analysis on multiple files for  
> &nbsp;&nbsp;&nbsp;&nbsp;the same participant?? Furthermore, how do we run analysis on  
> &nbsp;&nbsp;&nbsp;&nbsp;multiple subjects and multiple files? Will a FIF file be compatible  
> &nbsp;&nbsp;&nbsp;&nbsp;with statistical analysis?? The real issue that our lab sees is how  
> &nbsp;&nbsp;&nbsp;&nbsp;will be able to create component scores that can be output to other  
> &nbsp;&nbsp;&nbsp;&nbsp;programs for statistical analysis, primarily R.? There's a hint  
> &nbsp;&nbsp;&nbsp;&nbsp;about how to do this at the start of the scripts on this page after  
> &nbsp;&nbsp;&nbsp;&nbsp;the from import statements:  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;[https://martinos.org/mne/stable/auto\_examples/connectivity/plot\_mne\_inverse\_envelope\_correlation.html#sphx-glr-auto-examples-connectivity-plot-mne-inverse-envelope-correlation-py](https://martinos.org/mne/stable/auto_examples/connectivity/plot_mne_inverse_envelope_correlation.html#sphx-glr-auto-examples-connectivity-plot-mne-inverse-envelope-correlation-py)  
> &nbsp;&nbsp;&nbsp;&nbsp;\>?  
> &nbsp;&nbsp;&nbsp;&nbsp;\> However, maybe we require further explanation as we are not  
> &nbsp;&nbsp;&nbsp;&nbsp;interested necessarily in one subject at a time rather ALL subjects  
> &nbsp;&nbsp;&nbsp;&nbsp;at a time.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>?  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Thank you in advance for any insight that you may be able to  
> &nbsp;&nbsp;&nbsp;&nbsp;provide on these matters and of course your time.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>?  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Best,  
> &nbsp;&nbsp;&nbsp;&nbsp;\> UNLV PEPLab  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Bianca Islas  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Research Assistant  
> &nbsp;&nbsp;&nbsp;&nbsp;\> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Mne\_analysis mailing list  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Mne\_analysis at nmr.mgh.harvard.edu  
> &nbsp;&nbsp;&nbsp;&nbsp;\<mailto:Mne\_analysis at nmr.mgh.harvard.edu\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> [https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne\_analysis](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)
> 
> &nbsp;&nbsp;&nbsp;&nbsp;\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> &nbsp;&nbsp;&nbsp;&nbsp;Mne\_analysis mailing list  
> &nbsp;&nbsp;&nbsp;&nbsp;Mne\_analysis at nmr.mgh.harvard.edu  
> &nbsp;&nbsp;&nbsp;&nbsp;\<mailto:Mne\_analysis at nmr.mgh.harvard.edu\>  
> &nbsp;&nbsp;&nbsp;&nbsp;[https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne\_analysis](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Mne\_analysis mailing list  
> Mne\_analysis at nmr.mgh.harvard.edu  
> [https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne\_analysis](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)

-------------- next part --------------  
A non-text attachment was scrubbed...  
Name: signature.asc  
Type: application/pgp-signature  
Size: 488 bytes  
Desc: OpenPGP digital signature  
Url : [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20190807/f1717911/attachment.bin](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190807/f1717911/attachment.bin)  
-------------- next part --------------  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;External Email - Use Caution  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20190807/f1717911/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190807/f1717911/attachment.html)
