excel linear regression trouble vs excel linear regression

5 Ansichten (letzte 30 Tage)
Kolton Jones
Kolton Jones am 12 Apr. 2019
Bearbeitet: John D'Errico am 13 Apr. 2019
I am trying to find the equation for the linear regression line of x and y.
I was able to get the linear regression from excel, but I am trying to find it with matlab.
Excel says the linear regression equation is y = -0.003x + 1.7919.
x = 5.92 22.75 73.26 227.56 308.74 589.54 613.66
y = 2.550865 1.869146 1.1623 0.567358 0.459001 0.248734 0.225807
beta = regress(y',x')
% I had to rotate the arrays otherwise the function would not give an answer
the function spits out beta = 7.9666e-04.

Antworten (1)

John D'Errico
John D'Errico am 13 Apr. 2019
Bearbeitet: John D'Errico am 13 Apr. 2019
Simple enough.
polyfit(x,y,1)
ans =
-0.002965 1.7919
Or:
regress(y',[x',ones(length(x),1)])
ans =
-0.002965
1.7919
Or:
[x',ones(length(x),1)]\y'
ans =
-0.002965
1.7919
I could go on for at least a half dozen others. Don't dare me. ;-) With the curve fitting toolbox...
fit(x',y','poly1')
ans =
Linear model Poly1:
ans(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = -0.002965 (-0.005117, -0.0008127)
p2 = 1.792 (1.03, 2.554)
>> lsqr([x',ones(length(x),1)],y')
lsqr converged at iteration 2 to a solution with relative residual 0.34.
ans =
-0.002965
1.7919
>> lsqlin([x',ones(length(x),1)],y')
ans =
-0.002965
1.7919
>> lsqminnorm([x',ones(length(x),1)],y')
ans =
-0.002965
1.7919
>> pinv([x',ones(length(x),1)])*y'
ans =
-0.002965
1.7919
>> lscov([x',ones(length(x),1)],y')
ans =
-0.002965
1.7919
Wanna bet I can't come up with a half dozen more? Save your money. :)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by