cvnlab / GLMsingle

A toolbox for accurate single-trial estimates in fMRI time-series data
BSD 3-Clause "New" or "Revised" License
97 stars 42 forks source link

Trials at very end of run cause singularity problems #56

Open kendrickkay opened 2 years ago

kendrickkay commented 2 years ago

If an experiment has events coded very close to the end of an fMRI time-series run, after convolution with an HRF, the experimental predictor might be basically all 0s, and hence leads to estimation problems (singular design matrices).

This is the "experimenter's fault". But we should warn the user if this is happening.

The simple fix would be to not code those events (since it is impossible to estimate a beta response amplitude for those cases anyway!)

Aakashagr commented 2 years ago

Hello, I am facing the singular design matrix problem while fitting the type-B model (during the cross-validating step). Following your suggestion of not coding the events towards the end solved this problem. However, I had to exclude all events in the last 15 volumes of brain scans (TR = 2, stimdur = 1).

Can you please confirm if GLMsingle expects no events for such a long duration towards the end?

Thanks, Aakash

kendrickkay commented 2 years ago

I am somewhat surprised if you had to exclude the trials in the last 30 s of your run. I would guess that giving ~10 s of time would be enough (since the HRF for sure rises by about 10 s after onset). Maybe you can show pictures or send your design input variable?

(Alternatively, maybe there is some other aspect of your design that is causing problems. E.g., do you have some jitter / blank trials / dead time somewhere in your experimental runs?)

Aakashagr commented 2 years ago

Thank you for your prompt response. Indeed it was some aspect of the design matrix that caused this problem. If I add an extra regressor corresponding to blank trials (3rd column in the attached figure), I get the singularity issue. Excluding this column solves the issue. Alternatively, I will have to exclude all events after 170 time points to run the script without any error.

Maybe I am missing something here. I still don't understand why should the blank trial regressor give rise to the singularity problem. I could have presented another stimulus instead of blank trials, and it would have resulted in the same design matrix as now.

condmat_2

kendrickkay commented 2 years ago

Yes, the blank trial issue makes sense. The issue is that the GLM used in GLMsingle automatically includes some low order polynomials to account for baseline signal level. So, if you code every single trial (including blanks), then it becomes impossible (basically) to distinguish the trials from the polynomials. Basically, a overall signal increase (constant throughout the time series) is equally modelable as an increase in the constant polynomial OR a uniform increase for all of your trials.

We talk a bit about the issue of blanks on the FAQ: https://glmsingle.readthedocs.io/en/latest/wiki.html#faq which might be useful to read

Aakashagr commented 2 years ago

Yeah, I get it now. I missed the wiki section earlier. Thanks for pointing it out here. It answered some of my other general queries as well.