Nirstorm / nirstorm

Brainstorm plugin for fNIRS data analysis
GNU General Public License v3.0
34 stars 11 forks source link

More Generic API for GLM #129

Closed Edouard2laire closed 4 years ago

Edouard2laire commented 4 years ago

Hi @thomas-vincent

This discussion is related to the last lab meeting we had with the NIRSTORM team and #117.

Context:

Those 3 points are all related to GLM. In the first two we say Y=XB + e and we want to return e, therefore removing the effect of the regressor in X. In the first case X contains DCT, in the second X contains the value of the SSC. The thirds case, is also similar but we want B.

Problem:

As you have seen, adding a new regressor in X is not easy and therefore your addition in #115 is really hard to maintain and to understand for exemple if we were to add new regressor such as accelerometer data.

What I suggest:

Having a small structure called model that contains our GLM, and a set of function that will interact with it to do what we want : - add regressor, fit the data, display the design matrix...

The structure:

API:

Its quite easy to do, as all the material exist. but can really simplify the code for case 1, and 2 : 1/

model=initialize_model(ntime,fs) 
model= add_regressors(model, "DCT",  freq, freq_name);
B=model_fit_B(model, y);
y= y - X*B;   

2/

model=initialize_model(ntime,fs) 
model= add_regressors(model, "channel", superfical_chann);
B=model_fit_B(model, y);
y= y - X*B;   

Don't hesitate if you have comment :) Best regards, Edouard

Edouard2laire commented 4 years ago

Hi @thomas-vincent

Capture d’écran 2020-05-26 à 14 54 24

This is working nicely, and can remove trend in the data and is able to keep the mean if applied on raw data.

Maybe we want to add a condition to check that the regressor at not too correlated and then maybe add only meaningful time-course (maybe add the mean, or do more advance stuff like PCA..)

Capture d’écran 2020-05-27 à 15 48 01

Capture d’écran 2020-05-27 à 15 39 27

The main changes is that before, when applying the high-pass filter on the design matrix. We were assuming that the constant regressor was at the end, or with your changes in #115 , It was no longer true and it might have cause trouble. So I fixed that.

I also add the possibility to let the user say which filter he used for detrending (either IIR, or the new detrending process that I would recommend)

I therefore have a question when filtering the design matrix. Let say we have this simple design : model

When using IIR filter on it (low-cutoff = 0.05 = 1/200), we obtains :

model

When using detrending ( only constant and linear), we obtains : model

When using detrending ( only constant and linear and DCT cutoff = 0.05 = 1/200 ), we obtains : model

I have the feeling that we are introducing distortion to the HRF when using IIR filter, or when adding DCT in the detrending. Maybe we want to only remove the mean ? But I guess it's mandatory to apply the same filter that was applied on the data on the design matrix. What do you think ?

Another change is that I add the possibility to add nuisance regressor such as short-distance separation channel. We have here the same issue as before as adding more regressor might create trouble of conditioning of the matrix. What do you think of that ? I saw in a recent article about connectivity that they are only regressing out the mean of the short-distance channel. Might be a good idea. What do you think ?

Best regards, Edouard

Edouard2laire commented 3 years ago

NIRSTORM_Fig