필터 지우기
필터 지우기

Why do regression coefficients obtained from Excel and Matlab differ?

조회 수: 4 (최근 30일)
Marina
Marina 2014년 4월 18일
댓글: Marina 2014년 4월 18일
Hi
I would like to run a regression on the following matrices: X(m,1) and Y(m,1). I wan to run a polynomial regression of order 15. I have used: 1. Method 1: b - polynomial order (I even increased precision with vpa, but that did not make any difference)
XM=ones(size(X,1),b);
for f=1:b
H=vpa(X);
XM(:,f+1)=H.^f;
end
Beta=pinv(XM'*XM)*(XM'*Y)
ExpCont=XM*Beta
2. Method 2
BetaP=polyfit(X,Y,b)
ExpContP=polyval(BetaP,X)
Both methods resulted in the same result.
I have run regressions with the same input in Excel and Matlab. For an order 2 polynomial, the difference is insignificant. For higher order polynomials, the coefficients are not even close!!! Sometimes they even have opposite signs!!!! This results in a difference in the output.
Why are they different?

채택된 답변

dpb
dpb 2014년 4월 18일
...want to run a polynomial regression of order 15.
very, Very, VERY, bad idea!!!
The differences are caused by numerical precision with such large powers owing to differences in how the normal equations are formed and solved.
For a practical solution, use something other than such a fitting form, say piecewise splines or the like.
Why do you think you need/want such a high-order polynomial, anyway?
  댓글 수: 3
John D'Errico
John D'Errico 2014년 4월 18일
I'll amplify what dpb said. An insane idea.
High order polynomials like that will end up with virtually random coefficients due to numerical issues. Depending on how the data was shipped from one language to the other, you may have lost a bit or so in the least significant bits. That subtle difference is sufficient to see a difference when you compute that high order a polynomial. On top of that, the algorithm chosen by either system to compute the regression coefficients can easily have a huge impact on a problem like this.
By the way, the first method you showed was a TERRIBLE choice in terms of the numerics. Better would have been:
Beta = pinv(XM)*Y;
But even so, 15th degree is insane most of the time, and generally a complete waste of bits.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by