excel linear regression trouble vs excel linear regression

조회 수: 5 (최근 30일)
Kolton Jones
Kolton Jones 2019년 4월 12일
편집: John D'Errico 2019년 4월 13일
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.

답변 (1개)

John D'Errico
John D'Errico 2019년 4월 13일
편집: John D'Errico 2019년 4월 13일
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. :)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by