source-space analysis on MNE

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

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, 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), dtype=np.float)
design_matrix = np.column_stack <numpy.column_stack — NumPy v1.26 Manual([intercept, # intercept
                                 np.linspace <numpy.linspace — NumPy v1.26 Manual(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(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.

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

Hi Jona,

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

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>. 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

Hi Jona,

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

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. 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, 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), dtype=np.float)
design_matrix = np.column_stack <numpy.column_stack — NumPy v1.26 Manual([intercept, # intercept
                                 np.linspace <numpy.linspace — NumPy v1.26 Manual(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(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.

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