accuracy of coefficients using fit with power1

12 次查看(过去 30 天)
I'm seeing a discrepency between the coefficients obtained via MATLAB's fit function using a fitType of power1 and the coefficients provided with the same data using two other stats packages, one of which is Excel. The other is JMP, which agrees with Excel. So, I'm thinking the Excel and JMP values are likely correct. Here's a simple data set:
x = [1 2 3 4 5]
y = [9.58 10.90 12.56 13.41 14.33]
Using MATLAB, I get...
>> f = fit(x',y','power1')
f =
General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 9.384 (8.774, 9.994)
b = 0.2592 (0.206, 0.3125)
Using the same data and a power fit, the a and b coefficients with Excel and JMP are different, however. They both give
a = 9.4293
b = 0.9871
Any idea what might be causing this discrepency?
  1 个评论
Scott MacKenzie
Scott MacKenzie 2020-2-8
Oops, I just realized I mistyped the b coefficient from Excel and JMP. I typed the R^2 value by mistake. Sorry. So, to get it right, the MATLAB coefficients are...
a = 9.384
b = 0.2592
The Excel and JMP coefficents, for the same power fit, are...
a = 9.4293
b = 0.2544
The model is...
y = a x^b
The data are at the top of my original question.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-2-8
The Excel coefficients are what you get if you transform
t == a*x^b
using a log transform to get
log(t) == log(a) + b * log(x)
and then do a first degree polynomial fit, remembering to take exp() of the linear term (the second one in the polyfit coefficients) . This is least squared in log of x, but not least squared in x itself.
The coefficients that MATLAB gives are least squared in the original problem domain.
You can do calculus analysis on
r = sum( (a*x^b - t).^2 )
to minimize that by a = 9.38329520500233 b = 0.259283233448218

更多回答(2 个)

the cyclist
the cyclist 2020-2-7
编辑:the cyclist 2020-2-7
I don't have the Curve Fitting Toolbox, so I can't investigate directly. If you have the Statistics and Machine Learning Toolbox, then you can do
x = [1 2 3 4 5]';
y = [9.58 10.90 12.56 13.41 14.33]';
tbl = table(x,y);
f = @(F,x) F(1) * x.^F(2);
beta0 = [1 1]
mdl = fitnlm(tbl,f,beta0)
mdl =
Nonlinear regression model:
y ~ F1*x^F2
Estimated Coefficients:
Estimate SE tStat pValue
________ ________ ______ __________
F1 9.3838 0.19166 48.96 1.8763e-05
F2 0.25924 0.016743 15.483 0.00058531
Number of observations: 5, Error degrees of freedom: 3
Root Mean Squared Error: 0.234
R-Squared: 0.989, Adjusted R-Squared 0.985
F-statistic vs. zero model: 6.9e+03, p-value = 3.21e-06
As you can see, this agrees with your MATLAB result.
I am about as confident as I can be that the MATLAB result is correct. Could you upload the Excel file that is giving a different result? (Does it require a special plug-in?)
  3 个评论
John D'Errico
John D'Errico 2020-2-8
+1. Exactly correct. The coefficients claimed to be from both Excel and JMP are clearly bogus. The resulting curve will not pass anywhere near the data.
Usually the reason is that the wrong model is being used, or the wrong data was transported over. But all you need to do is plot the two models, compared to the data to see the claimed parameters are complete crap for this data. cyclist did exactly that.
I played around for just a bit, trying to see if there was any obvious mistake made. I.e., could those parameters belong to some other fit to the same data, but I did not see anything obvious, or any simple transformation of the data what would yield the indicated set of parameters.
Scott MacKenzie
Scott MacKenzie 2020-2-8
John: I think our responses crossed. Please see my response posting. I'm still scratching my head over this. Any insight you can provide is greatly appreciated.

请先登录,再进行评论。


Scott MacKenzie
Scott MacKenzie 2020-2-8
Sorry, but I haven't a clue how to upload an Excel spreadsheet into this question. But, all you need to do is put the following five number in Excel: 9.58 10.90 12.56 13.41 14.33.
Then, select them, select Insert --> Chart --> Scatter. That will create the scatter plot. Then, select the point in the scatter plot, right-click on the points and select Add trendline. Just choose Power and make sure the "Display equation on chart" option is select. Click OK and voila. Here's a screengrab:
screengrab.JPG
Here a second screengrap from JMP/Statview, which shows the same coefficients:
screengrab2.JPG
Ah, I think I just figured out how to attach the spreadsheet. Here goes...

Community Treasure Hunt

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

Start Hunting!

Translated by