Power Regression - Matlab vs Excel

6 views (last 30 days)
Steve Sous
Steve Sous on 9 Oct 2015
Edited: dpb on 12 Oct 2015
Hi Everyone The following code:
x = [1 2 3 4 5 6 7 8 9 10]';
y = [2 1 3 5 2 1 3 4 7 9]';
f = fit(x,y,'power1')
Will give
General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 0.2774 (-0.4832, 1.038)
b = 1.425 (0.1224, 2.728)
But in Excel, the same data gives us:
y = 1.2519*x ^0.5611
so:
a = 1.2519
b = 0.5611
Why are are both power regression models so different in Matlab and Excel? How can i get the same Excel results in Matlab?

Answers (2)

dpb
dpb on 10 Oct 2015
Edited: dpb on 12 Oct 2015
Didn't show your work in Excel so can't judge what went on there, but I don't know why you'd choose that model over the Matlab result after
>> x = [1 2 3 4 5 6 7 8 9 10]';
y = [2 1 3 5 2 1 3 4 7 9]';
>> yhM=0.2774*x.^1.425; % Matlab yhat
>> yhE=1.2519*x.^0.5611; % and Excel...
>> [var(y-yhM) var(y-yhE)] % fitted residual error
ans =
3.1309 4.2505
>> plot(x,[y yhM yhE])
>> legend('Data','Matlab','Excel','location','northwest')
>>
The Matlab fitted results has a residual of roughly 30% smaller (albeit given the noise in the input y vector, neither is all that great a fit) and clearly follows the gross overall shape more nearly than does the Excel result.
ADDENDUM After thinking about the results from Excel w/ the power being roughly square root and hence the shape being convex, it came to me that I wonder if transposed the x,y vectors in Excel--so,
>> fit(y,x,'power1')
ans =
General model Power1:
ans(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 2.768 (0.5397, 4.996)
b = 0.5615 (0.08159, 1.041)
>>
Indeed, the exponents are almost identical so I'm betting that's what went wrong in Excel; you didn't set up the input correctly. Not sure what might've been the actual values such that the multiplier coefficient a is roughly half the size but likely didn't have the data there intended, either.

Image Analyst
Image Analyst on 11 Oct 2015
Try fitnlm() instead.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!