Difference linear regression / linear solver
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2017-6-26
To answer your question, we must have more information about your regression problem.
Best wishes
Torsten.
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
2017-6-26
编辑:dpb
2017-6-26
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
>>
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!