Difference linear regression / linear solver
Mostra commenti meno recenti
Hi I have a theoretical question.
I run a linear regression using fitlm that showed good results. Then, I wanted to introduce some constraints, therefore I applied lsqlin. However, the results using lsqlin were very different compared to fitlm, even if I don't use the constraints.
Could you please explain to me what is the main difference the linear regression and the solver, that may contribute to different results?
Thank you Lisa
3 Commenti
Joshua
il 26 Giu 2017
Lisa,
I don't know a ton about linear regression, but this link suggests that one function could be forcing your line to a certain y-intercept while the other one is not.
https://www.mathworks.com/matlabcentral/answers/269435-what-is-the-difference-between-the-regress-function-and-the-fitlm-function
If the link doesn't help just carefully read the documentation. It is not particularly fun, but it probably will give you the answer. Helps me a lot. If that doesn't work, post your code with the data set and solutions so we can see what exactly is going wrong.
Torsten
il 26 Giu 2017
To answer your question, we must have more information about your regression problem.
Best wishes
Torsten.
dpb
il 26 Giu 2017
As Torsten says, only way to provide any specific answer would require the code and data. For the no constraints case one should get same result as lsqlin returns x = C\d which is OLS solution.
Risposte (1)
As commented above, if given same problem, all return same result--
>> x=1:10;y=x+rand(size(x));
>> b=polyfit(x,y,1)
b =
0.9631 0.7126
>> fit(x.',y.','poly1')
ans =
Linear model Poly1:
ans(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.9631 (0.8776, 1.049)
p2 = 0.7126 (0.1825, 1.243)
>> [x.' ones(length(x),1)]\y.'
ans =
0.9631
0.7126
>> lsqlin([x.' ones(length(x),1)],y.')
ans =
0.9631
0.7126
>>
As can be seen, all give the same result.
One can only presume perhaps you left out the ones column in the design matrix for the constant term in the lsqlin case?
>> lsqlin(x.',y.') % zero intercept model...
ans =
1.0649
>>
>> [x.' ]\y.'
ans =
1.0649
>>
Categorie
Scopri di più su Linear Least Squares in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!