Rank deficiency when trying to use fitlm

12 views (last 30 days)
ohmstead
ohmstead on 20 Mar 2019
Answered: Todd Harris on 9 Jun 2020
I am trying to fit a simple regression model to some data (y ~ 1 + x1). However, I am not getting an estimate for the y-intercept because my design matrix is rank-deficient (Note: Xs and Ys are large column vectors, 4502342x1):
>> fitlm(Xs,Ys)
Warning: Regression design matrix is rank deficient to within machine precision.
> In classreg.regr.CompactTermsRegression/checkDesignRank (line 35)
In LinearModel.fit (line 1236)
In fitlm (line 121)
ans =
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
________ _________ _______ ______
(Intercept) 0 0 NaN NaN
x1 -0.64712 0.0041947 -154.27 0
Number of observations: 3129429, Error degrees of freedom: 3129428
Root Mean Squared Error: 39.3
R-squared: 0.0852, Adjusted R-Squared 0.0852
F-statistic vs. constant model: Inf, p-value = NaN
I tried researching what rank deficiency means in this context, but didn't have much luck. When I take a subset of the data, e.g.:
rsam = randsample(length(Xs),round( length(Xs) / 100 ));
fitlm(Xs(rsam),Ys(rsam))
I have absolutely no trouble at all; output is great. Can anyone shed some light on this?
  4 Comments
dpb
dpb on 21 Mar 2019
OK, if it isn't related to not showing what actually generated the error, then the full vector contains data that are linear combinations of others. What does
rank(Xs)
return?

Sign in to comment.

Answers (1)

Todd Harris
Todd Harris on 9 Jun 2020
I was having this problem but managed to solve it by converting the input for the fitlm function to double (they were single originally). Hope this helps.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!