2
votes

This is the data I am using for Y data:

0.577032413537833
0.288198874369377
0.192282280031568
0.143824619265244
0.114952782524097
0.0960518606520442
0.0824041879978560
0.0719078360110914
0.0640919744028295
0.0572120310249072
0.0519630635470660
0.0479380073164273
0.0443712721513307

X is simply the integer value from 1 to 13 and I know that this is power function of form a*x^b+c from running GUI cftool on MATLAB with rather high R-square value (1)

To perform the fit on command line, I used:

>> g = fittype('a*x^b+c','coeff',{'a','b','c'})
>> x=1:13;
>> [c3,gof3] = fit(x',B3(:,1),g)

This results in

c3 =

 General model:
   c3(x) = a*x^b+c
 Coefficients (with 95% confidence bounds):
   a =        -179  (-1.151e+005, 1.148e+005)
   b =    0.001066  (-0.6825, 0.6847)
   c =       179.5  (-1.148e+005, 1.151e+005)

gof3 =

       sse: 0.0354
   rsquare: 0.8660
       dfe: 10
adjrsquare: 0.8392
      rmse: 0.0595

Which is not the same as

General model Power2:
       f(x) = a*x^b+c
Coefficients (with 95% confidence bounds):
   a =      0.5771  (0.5765, 0.5777)
   b =      -1.001  (-1.004, -0.9983)
   c = -8.972e-005  (-0.0005845, 0.000405)

Goodness of fit:
  SSE: 4.089e-007
  R-square: 1
  Adjusted R-square: 1
  RMSE: 0.0002022

That I get when I run the regression on cftool GUI interface. What options I am missing here that gives me rather different results on seemingly the model? That a = -179 is very fishy....

Thanks in advance for your inputs.

Oh also, once I sort those out, is there way to get only particular value from fitted model? Say, I am only interested in values of A.

for gof, I know I can extract out by using gof.rsquare... and so on, but how about for cfit?

1
It turns out all I have to do to extract the coefficients was c3.a c3.b and so on. Not sure why it didn't work last time I tried.user1426485

1 Answers

4
votes

When I tried doing

>> g = fittype('a*x^b+c','coeff',{'a','b','c'})
>> x=1:13;
>> [c3,gof3] = fit(x',B3(:,1),g)

I got

Warning: Start point not provided, choosing random start point. 
> In Warning>Warning.throw at 31
  In fit>iFit at 320
  In fit at 109 

So I changed it to

>> [c3,gof3] = fit(x', B3(:,1),g, 'Startpoint', [0 0 0])

which gives me

c3 = 

     General model:
     c3(x) = a*x^b+c
     Coefficients (with 95% confidence bounds):
       a =      0.5771  (0.5765, 0.5777)
       b =      -1.001  (-1.004, -0.9983)
       c =  -8.972e-05  (-0.0005844, 0.000405)

which is indeed a lot closer to the one you got from the cftool GUI.

Quite possibly the "random start point" was a lot better for the GUI than it was for the CLI fit, so you were just lucky.

If these results can be produced consistently, well, then the GUI must be programmed to also use the Global optimization toolbox when available, or some similar scheme. But that's just wild speculation.