How to force my robust regression to pass through y=1?

4 visualizaciones (últimos 30 días)
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')

Respuesta aceptada

John D'Errico
John D'Errico el 13 de Nov. de 2017
Editada: John D'Errico el 13 de Nov. de 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 comentarios
Walter Roberson
Walter Roberson el 17 de Nov. de 2017
Carlos asks,
Does anyone know a solution for my question? Thanks.
Walter Roberson
Walter Roberson el 17 de Nov. de 2017
kstest2() possibly.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by