How to force my robust regression to pass through y=1?
1 view (last 30 days)
Show older comments
Carlos Goncalves Moreira
on 13 Nov 2017
Commented: Walter Roberson
on 17 Nov 2017
I have a very simple code with two vectors. I want to compute a robust regression on those values, but forcing the function to pass in y(0)=1. I tried to apply the polyfit function, but honestly I don't have much experience with Matlab. Does anyone have a simple solution for this, so I can extract my statistic results? Thanks
x=[1 1 1 1 1 1 28 28 28 28 28 28 56 56 56 56 56 56 84 84 84 84 84 84 112 112 112 112 112 112];
of_wt_veh=[1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0.739660 0.697400 0.604162 0.748125 0.683022 0.761243 0.984600 0.675027 0.639655 0.662086 0.660443 0.845765 1.126925 0.709459 0.828230 0.604704 0.635310 0.783181 1.019504 0.640609 0.462813 0.616220 0.754486 0.6987264];
[b,stats] = robustfit(x,of_wt_veh);
scatter(x,of_wt_veh,'filled'); grid on; hold on
plot(x,b(1)+b(2)*x,'g','LineWidth',2)
legend('Data','Robust Regression')
0 Comments
Accepted Answer
John D'Errico
on 13 Nov 2017
Edited: John D'Errico
on 13 Nov 2017
Use robustfit with no constant term. But subtract 1 from y.
That forces the fit to pass through y==1, at x==0.
b(1) = 1;
[b(2),stats] = robustfit(x,of_wt_veh - 1,[],[],'off');
The point is, if your fit has no constant term in a polynomial, then it goes through (0,0). EXACTLY. ALWAYS. So if you subtract 1 from y, then you want the fit to go through 0.
5 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!