You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Linear Mixed Effects Models: numpy.linalg.LinAlgError: Singular matrix #6140
I'm going to find the correlation between the contribution of each type and the 'score'. So I use the proportion of each type as X, the score as Y. I have 150 types and obviously each sample has: x1+x2+...x150=1. Y(score) ∈(0,10) and Y is float. Xi ∈[0,1] and also is float. Each sample has the lable 'region' which shows the area it comes from. I want to use the mixed liner model, where the 150 types(x1,x2...x150) make fixed effect and the 'region' makes the random effect.
I have tried:
but got the error: numpy.linalg.LinAlgError: Singular matrix
Does this mean that there is collinearity in my data? I think the answer is yes, I have following questions:
Is there any ways for me to fix the collinearity, such as fine the samples pair which has collinearity. After that maybe I can drop some samples.
Does this mean that my data situation is not suitable for mixed linear models? But if I really need to take into account the impact of spatial relationships, whatshould I do?
I think the statsmodels use Maximum Likelihood Estimation to fix the mixed liner model and use linalg.py( of numpy) to solve a linear matrix equation ax = y. But the file (linalg.py) requests a must be square and of full-rank, i.e., all rows (or, equivalently, columns) must be linearly independent; if either is not true, use lstsq for the least-squares best "solution" of the system/equation.' So probably OLS is suitable for my data?
The elements of 's' are the singular values of the fixed effects design matrix. The more zeros (or extremely small values) there are in 's', the more collinearity you have. Non-convergence can happen for other reasons besides collinearity, so it is good to start with this check.
Dropping samples will only make things worse. It seems that your regression model is not identified. In general, that means that you should eliminate covariates until you get an identified regression. If you want to automate this process, you could use scipy.qr with pivot=True to find a maximal set of linearly independent columns of your design matrix.
Activity
kshedden commentedon Aug 29, 2019
I would start with this:
The elements of 's' are the singular values of the fixed effects design matrix. The more zeros (or extremely small values) there are in 's', the more collinearity you have. Non-convergence can happen for other reasons besides collinearity, so it is good to start with this check.
KaninchenM commentedon Sep 4, 2019
A good way to inspect collinearity. Thank you so much. But I still haven't found a good way to process my data. Hope I can find and update here later.
kshedden commentedon Sep 4, 2019
Dropping samples will only make things worse. It seems that your regression model is not identified. In general, that means that you should eliminate covariates until you get an identified regression. If you want to automate this process, you could use scipy.qr with pivot=True to find a maximal set of linearly independent columns of your design matrix.