MATLAB Answers

mr mo

Multiple Linear Regression creates same results as the Target values

Asked by mr mo
on 12 Feb 2018
Latest activity Commented on by Jelle
on 13 Feb 2018
Hi. I have to use the Multiple linear Regression in Matlab. I have the X matrix of size 10*1000 and Y Matrix of size 10*1. I use this code
b = regress(Y,X);
and then I use this
to find the values of vector b that are inequal to zero. assume that this is the result of above code
s= 2 7 95 172 290 333 471 560 680 890
then I use this
for i=1:size(X,1)
to create the output values.
But the output values is same as the Y values.
Did I make a mistake some where or the code is true ?
Thanks a lot.


Sign in to comment.

1 Answer

Answer by Jelle
on 13 Feb 2018

If you have more predictors in your regression than you have values to predict you will get a perfect prediction model.
In other words: If you have 10 measurements, and 10 variables that could be related to these measurements, you can fit a model that perfectly explains the variation in the measured variables. This is called overfitting. In practice, only 1 or 2 variables really explain what is going on. The rest is just 'filling the gaps'
I would recommend looking at stepwise regression if you do not know which of the 1000 predictors in X are the ones you need. The check the p-value for the predictor to see how likely it is that predictor is just a random variable.


Thanks for your help. How can I use stepwise regression in this case?
Cannot help you with the actual implementation: I have not used the stepwise model in matlab. It is here, and seems straightforward though:
Rather, I have build a stepwise fitter myself, as my goal was not the best fitting regression, but an estimate of the reliability of the fitting (

Sign in to comment.