How do i pass atrendline through zero?

2 visualizaciones (últimos 30 días)
Parth Sarathi
Parth Sarathi el 15 de Mzo. de 2016
Editada: Ced el 15 de Mzo. de 2016
I have a data when fit gives rise to an equation y=1.09x+0.23. However i want to pass the trend line through zero and get an equation y=1.234x. Can anyone please help how to do that?
  1 comentario
KSSV
KSSV el 15 de Mzo. de 2016
Your question sounds funny. The first equation is a straight line with slope 1.09 and intersecting y-axis at 0.23. Second equation is a straight line with slope 1.234 and passing through origin. What exactly are you trying?

Iniciar sesión para comentar.

Respuestas (1)

Ced
Ced el 15 de Mzo. de 2016
Editada: Ced el 15 de Mzo. de 2016
You need to set up your regression accordingly. If you don't want a y offset, you could just normalize your data, i.e. remove the mean on both sides, and then not add it back during the prediction. Be aware that you are introducing an error though!
Alternatively, you can just remove the bias from the optimization.
As Dr. Siva Srinivas Kolukula correctly pointed out though, I don't know why you would want to do this though.
Here is a small example:
x = linspace(-4,4,20)';
N = length(x);
y = 1.09*x+2 + 1*randn(N,1);
% estimate with offset: y = a1*x + b1 = x*beta1
Phi1 = [ x ones(N,1) ];
beta1 = (Phi1'*Phi1)\Phi1'*y;
% estimate without offset: y = a2*x = x*beta2
Phi2 = x;
beta2 = (Phi2'*Phi2)\Phi2'*y;
% estimate without offset: y = a2*x = x*beta2
Phi2 = x;
beta2 = (Phi2'*Phi2)\Phi2'*y;
% estimate with normalized data
% y_norm = a2*x_norm = x_norm*beta2
xmean = mean(x);
ymean = mean(y);
Phi3 = x-xmean;
beta3 = (Phi2'*Phi2)\Phi2'*(y-ymean);
figure()
plot(x,y,'x');
hold on
plot(x,Phi1*beta1)
plot(x,Phi2*beta2);
% NOTE: not adding offset!!
plot(x-xmean,Phi3*beta3,'--');
grid on
xlabel('x')
ylabel('y')
legend('samples','affine fit','linear fit','fit without offset')

Categorías

Más información sobre Smoothing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by