Difference linear regression / linear solver
4 visualizzazioni (ultimi 30 giorni)
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
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)
dpb
il 26 Giu 2017
Modificato: dpb
il 26 Giu 2017
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 Commenti
Vedere anche
Categorie
Scopri di più su Linear Least Squares in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!