mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

BUG..?: linear_regression_raw doesn't warn for rank deficiency

Open jona-sassenhagen opened this issue 10 years ago • 9 comments

Passing predictors that will lead to a rank deficient matrix to linear_regression_raw should throw an error or at least a big fat warning. Currently, it silently computes a stupid solution. This is in my experience a very common scenario.

An extremely easy way may be checking the rank of the resulting predictor matrix.

(It would also be nice to estimate the degree of multicollinearity in the model.)

jona-sassenhagen avatar Jan 11 '16 02:01 jona-sassenhagen

how would you do this?

agramfort avatar Jan 11 '16 09:01 agramfort

I'm not sure - the problem is, how to do it on the cheap? np.matrix_rank uses an SVD which I assume takes about as long as the actual regression.

Another option I could explore might be doing it with the much smaller input matrices, but that would only approximate it.

jona-sassenhagen avatar Jan 11 '16 13:01 jona-sassenhagen

you can solve the system with an SVD so you know before solving the system if you have a conditioning pb.

agramfort avatar Jan 11 '16 13:01 agramfort

I'll start trying things out once I've brought a few of my other PRs home ... I'd also extend the docstring a bit.

jona-sassenhagen avatar Jan 11 '16 13:01 jona-sassenhagen

As discussed with @Eric89GXL , I will catch the linalg error the Cholesky solver gives for a perfectly collinear pair of predictors and replace it with a more helpful warning telling people to fix their model.

jona-sassenhagen avatar Mar 28 '17 18:03 jona-sassenhagen

@jona-sassenhagen did you fix this in some recent PR?

larsoner avatar Apr 18 '17 13:04 larsoner

Nope. We discussed it at the sprint a bit, but for now I'd wait for https://github.com/mne-tools/mne-python/pull/3563

jona-sassenhagen avatar Apr 18 '17 13:04 jona-sassenhagen

Hi! I’m Aditya, a student preparing for GSoC 2025 and exploring open-source contributions. This issue looks interesting, and I’d love to work on it as my first contribution. Could you please assign it to me or let me know if it’s available? Thanks!

NadipilliAditya avatar Apr 07 '25 16:04 NadipilliAditya

It's still available!

larsoner avatar Apr 08 '25 17:04 larsoner