# source-space analysis on MNE

**URL:** <https://mne.discourse.group/t/source-space-analysis-on-mne/1289>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 28, 2017, 6:57pm UTC](https://mne.discourse.group/t/source-space-analysis-on-mne/1289 "2017-08-28T18:57:19Z")\
**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 28, 2017, 6:57pm UTC](https://mne.discourse.group/t/source-space-analysis-on-mne/1289/1 "2017-08-28T18:57:19Z")

</div>

Hello,

I apologize for improper use of vocabulary or any misunderstanding of how MNE works - I just started learning it.

I found out that MNE provides two functions to calculate regression on EEG signal - linear\_regression and linear\_regression\_raw, with the former working on epoched data and the latter working on continuous data.

I have a couple of question regarding setting up predictors, and I was hoping someone could help. First - is the parameter for predictors design\_matrix in the linear\_regression function? What about linear\_regression\_raw?  
If design\_matrix does what I think it does, how can I make sure that the design\_matrix array matches the first dimension of the data to be regressed? Any suggestion on that?

Many thanks in advance!

-r

---

<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 30, 2017, 8:40am UTC](https://mne.discourse.group/t/source-space-analysis-on-mne/1289/2 "2017-08-30T08:40:22Z")

</div>

> Hi Jona,
> 
> many thanks for your reply.
> 
> So, linear\_regression\_raw will take predictors from the covariates argument, which will have to refer to an array having the same length as the event file - am I correct? What is the reasoning behind having two regression functions (one for continuous and one for non-continuous data)?

(The suggestion is to use pandas data frames for linear\_regression\_raw)  
They work completely differently. One fits independent models at each time point, the other fits one model for the whole data set.

> I was looking at the script here \<[Page Redirection](http://martinos.org/mne/dev/auto_examples/stats/plot_sensor_regression.html#sphx-glr-auto-examples-stats-plot-sensor-regression-py&gt;), and I was a bit unclear about some lines of code - I just started migrating from eeglab, so I apologize if I sound completely ignorant about everything here.
> 
> names = ['intercept', 'trial-count']
> 
> intercept = np.ones \<[numpy.ones — NumPy v1.26 Manual](http://docs.scipy.org/doc/numpy/reference/generated/numpy.ones.html#numpy.ones&gt;%5C(%5C(len%5C(epochs%5C),%5C)), dtype=np.float)  
> design\_matrix = np.column\_stack \<[numpy.column\_stack — NumPy v1.26 Manual](http://docs.scipy.org/doc/numpy/reference/generated/numpy.column_stack.html#numpy.column_stack&gt;%5C)([intercept, # intercept  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;np.linspace \<[numpy.linspace — NumPy v1.26 Manual](http://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace&gt;%5C)(0, 1, len(intercept))])  
> So, if I?m understanding correctly, here the code is defining one of the two predictors for the next regression analysis. `intercept` is an array as long as the variable `epochs`, and filled with ones. Such an array is ?glued? with another array of the same length, filled with evenly spaced numbers between 0 and 0. Everything is then put in the linear regression model:
> 
> # also accepts source estimates  
> lm = linear\_regression \<[mne.stats.linear\_regression — MNE 1.7.0.dev17+g20174f448 documentation](http://martinos.org/mne/dev/generated/mne.stats.linear_regression.html#mne.stats.linear_regression&gt;%5C)(epochs, design\_matrix, names)
> 
> My question is - what is `trial_count` in the first place? It is defined as follows:
> 
> trial\_count = lm['trial-count']  
> but I don?t seem to understand what that really is. Basically what I was trying to do is plotting rERP waveforms with the epoched regression function, similarly to what is showed for the non-epoched regression function here \<[Page Redirection](http://martinos.org/mne/dev/auto_examples/stats/plot_linear_regression_raw.html#sphx-glr-auto-examples-stats-plot-linear-regression-raw-py&gt;%5C).

trial\_count is the 2nd column of the design matrix. It?s, as you said, evenly spaced numbers from 0 to 1, so it?s 0 for the first and 1 for the last epoch. It gets its name from the ?names? list (defined further up) fed as the 3rd argument to linear\_regression.  
So it?s just a regressor for how late you are in the experiment.

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20170830/768583e6/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20170830/768583e6/attachment-0001.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 30, 2017, 1:57pm UTC](https://mne.discourse.group/t/source-space-analysis-on-mne/1289/3 "2017-08-30T13:57:43Z")

</div>

Hi Jona,

that makes sense. I have another couple of questions, if you don?t mind me asking. 🙂

1) I tried to use linear\_regression\_raw on my data, but I got the weird result attached. It looked like my data needed to be baseline-corrected (which isn?t apparently applied within the actual function), but I wouldn't know how to do it. Is it the apply\_baseline method that I should use for that purpose?

2) A way around the problem in 1) would be to use linear\_regression on already epoched and baseline-corrected data as shown here \<[http://martinos.org/mne/dev/auto\_examples/stats/plot\_sensor\_regression.html#sphx-glr-auto-examples-stats-plot-sensor-regression-py](http://martinos.org/mne/dev/auto_examples/stats/plot_sensor_regression.html#sphx-glr-auto-examples-stats-plot-sensor-regression-py)\>. Is there a plotting results other than the topomaps exemplified there?

3) I don?t seem to understand what some of the arguments of linear\_regression\_raw really say. In particular, which argument takes the predictors to run the regression against - covariates or solver? What does each of them actually do?

Many thanks for all the help, and apologies for the amount of questions!

-Roberto

---

<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:** [September 2, 2017, 4:53pm UTC](https://mne.discourse.group/t/source-space-analysis-on-mne/1289/4 "2017-09-02T16:53:37Z")

</div>

> Hi Jona,
> 
> that makes sense. I have another couple of questions, if you don?t mind me asking. 🙂
> 
> 1) I tried to use linear\_regression\_raw on my data, but I got the weird result attached. It looked like my data needed to be baseline-corrected (which isn?t apparently applied within the actual function), but I wouldn't know how to do it. Is it the apply\_baseline method that I should use for that purpose?

Yes, you can call .apply\_baseline on evoked objects. Or possibly filter the raw data harder.

> 2) A way around the problem in 1) would be to use linear\_regression on already epoched and baseline-corrected data as shown here \<[Page Redirection](http://martinos.org/mne/dev/auto_examples/stats/plot_sensor_regression.html#sphx-glr-auto-examples-stats-plot-sensor-regression-py&gt;%5C). Is there a plotting results other than the topomaps exemplified there?

The two are entirely different, but if linear\_regression covers your use case, you should go for it.

Both return evoked objects (one per condition for \_raw, and one each for t value, log p value, and beta for the epochs version per predictor). Try plotting the evoked objects with .plot\_joint(), or maybe .plot\_image.

> 3) I don?t seem to understand what some of the arguments of linear\_regression\_raw really say. In particular, which argument takes the predictors to run the regression against - covariates or solver? What does each of them actually do?

solver takes the solver - i.e., the algorithm to solve the linear system. covariates is one of two options for specifying predictors.

> Many thanks for all the help, and apologies for the amount of questions!
> 
> -Roberto
> 
> ----------  
> Roberto Petrosino  
> Ph.D. Student in Linguistics  
> CT Institute for the Brain and Cognitive Sciences  
> University of Connecticut
> 
> > > Hi Jona,
> > > 
> > > many thanks for your reply.
> > > 
> > > So, linear\_regression\_raw will take predictors from the covariates argument, which will have to refer to an array having the same length as the event file - am I correct? What is the reasoning behind having two regression functions (one for continuous and one for non-continuous data)?
> > 
> > (The suggestion is to use pandas data frames for linear\_regression\_raw)  
> > They work completely differently. One fits independent models at each time point, the other fits one model for the whole data set.
> > 
> > > I was looking at the script here \<[Page Redirection](http://martinos.org/mne/dev/auto_examples/stats/plot_sensor_regression.html#sphx-glr-auto-examples-stats-plot-sensor-regression-py&gt;), and I was a bit unclear about some lines of code - I just started migrating from eeglab, so I apologize if I sound completely ignorant about everything here.
> > > 
> > > names = ['intercept', 'trial-count']
> > > 
> > > intercept = np.ones \<[numpy.ones — NumPy v1.26 Manual](http://docs.scipy.org/doc/numpy/reference/generated/numpy.ones.html#numpy.ones&gt;%5C(%5C(len%5C(epochs%5C),%5C)), dtype=np.float)  
> > > design\_matrix = np.column\_stack \<[numpy.column\_stack — NumPy v1.26 Manual](http://docs.scipy.org/doc/numpy/reference/generated/numpy.column_stack.html#numpy.column_stack&gt;%5C)([intercept, # intercept  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;np.linspace \<[numpy.linspace — NumPy v1.26 Manual](http://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace&gt;%5C)(0, 1, len(intercept))])  
> > > So, if I?m understanding correctly, here the code is defining one of the two predictors for the next regression analysis. `intercept` is an array as long as the variable `epochs`, and filled with ones. Such an array is ?glued? with another array of the same length, filled with evenly spaced numbers between 0 and 0. Everything is then put in the linear regression model:
> > > 
> > > # also accepts source estimates  
> > > lm = linear\_regression \<[mne.stats.linear\_regression — MNE 1.7.0.dev17+g20174f448 documentation](http://martinos.org/mne/dev/generated/mne.stats.linear_regression.html#mne.stats.linear_regression&gt;%5C)(epochs, design\_matrix, names)
> > > 
> > > My question is - what is `trial_count` in the first place? It is defined as follows:
> > > 
> > > trial\_count = lm['trial-count']  
> > > but I don?t seem to understand what that really is. Basically what I was trying to do is plotting rERP waveforms with the epoched regression function, similarly to what is showed for the non-epoched regression function here \<[Page Redirection](http://martinos.org/mne/dev/auto_examples/stats/plot_linear_regression_raw.html#sphx-glr-auto-examples-stats-plot-linear-regression-raw-py&gt;%5C).
> > 
> > trial\_count is the 2nd column of the design matrix. It?s, as you said, evenly spaced numbers from 0 to 1, so it?s 0 for the first and 1 for the last epoch. It gets its name from the ?names? list (defined further up) fed as the 3rd argument to linear\_regression.  
> > So it?s just a regressor for how late you are in the experiment.

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20170902/2daa6fb2/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20170902/2daa6fb2/attachment-0001.html)
