Why do regression coefficients obtained from Excel and Matlab differ?
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Polynomials dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!