Difference linear regression / linear solver

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

Joshua
Joshua 2017년 6월 26일
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
Torsten 2017년 6월 26일
To answer your question, we must have more information about your regression problem.
Best wishes
Torsten.
dpb
dpb 2017년 6월 26일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2017년 6월 26일
편집: dpb 2017년 6월 26일

0 개 추천

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
>>

댓글 수: 2

Lisa
Lisa 2017년 6월 26일
Thank you very much. That exactly answered my question. I see now that there are the same results when adding the constant term. Another error of mine was that I used the option 'RobusOpt' in fitlm. These two aspects contributed to the different results.
One more question would be now: I wanted to use lsqlin instead of fitlm because of the option to set upper and lower bounds. Hence, would there be an option for lsqlin (or another function) to implement both robust fitting as well we upper and lower bounds?
Thanks
dpb
dpb 2017년 6월 27일
Don't think is a prepackaged routine to do both, no.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2017년 6월 26일

댓글:

dpb
2017년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by