MATLAB: How to use ‘regstats’ to make a multiple linear regression with more than three predictor variables

multilinear regressionmultiple linear regressionregressionregstatsstatistics

I am currently using the following code:
predictors = [Hs2 Dp2 Tp2 windvelocity windirection] % 12x5
Y = [LCvelocity] % 12x1
qualstat = {'rsquare'};
rsquare05 = regstats([LCvelocity],[predictors],...
'quadratic', qualstat);
r2=[rsquare05.rsquare]';
r=sqrt(r2)
Error using regstats (line 124)
The design matrix has more predictor variables than observations.
But the error keeps happening, unless I diminish the predictors matrix to a 12×3 size, in this case my code works. Anyone knows what is the problem?

Best Answer

You've asked for a full quadratic model in 5 (not 4) predictor variables. That's a total of 5 quadratic + 5 linear + 9 (4+3+2) interaction terms + 1 constant term --> 20 coefficients to estimate with only 12 observations.
ERRATUM
Actually, there are 21 coefficients, not 20...I knew something seemed peculiar but didn't catch it at the time.
...+ 10 (4+3+2+1) interaction terms ...
I left off the last cross term...now back to our regularly scheduled programming...dpb
With three predictors it's "only" 3+3+3+1 = 10 which is still way overfitting the data with only 2 DOF left but at least is computable.
ADDENDUM
You could start with a simple linear model of the five predictors and see what happens...of course, model fitting without first plotting to see what the data look like is like playing darts blindfolded.
And, with only 12 data points in 5-vector space, it's going to be very difficult to do very much, anyway; you just don't have enough points to cover the dimensionality.