Question

I'm calculating a polynomial fit using the mathowrks example:

load census
figure
plot(cdate,pop,'ro')
corrcoef(cdate,pop)

figure
% Calculate fit parameters
[p,ErrorEst] = polyfit(cdate,pop,2);
% Evaluate the fit
pop_fit = polyval(p,cdate,ErrorEst);
% Plot the data and the fit
plot(cdate,pop_fit,'-',cdate,pop,'+');
% Annotate the plot
legend('Polynomial Model','Data','Location','NorthWest');
xlabel('Census Year');
ylabel('Population (millions)');

enter image description here

How can I find the correlation of this fit? With a simple linear relationship I could calculate the fit using corrcoef but on the mathworks website they only mention "he following figure shows that the quadratic-polynomial fit provides a good approximation to the data" but dont go into any of the statistics.

Can anyone suggest a method?

http://www.mathworks.co.uk/help/matlab/data_analysis/programmatic-fitting.html

Was it helpful?

Solution

You could use the following:

ft_ = fittype('poly2');
[cf,gf,o] = fit(cdate,pop,ft_)

when I do this my results are:

cf = 

     Linear model Poly2:
     cf(x) = p1*x^2 + p2*x + p3
     Coefficients (with 95% confidence bounds):
       p1 =    0.006541  (0.006124, 0.006958)
       p2 =      -23.51  (-25.09, -21.93)
       p3 =  2.113e+004  (1.964e+004, 2.262e+004)

gf = 

           sse: 159.029299176792
       rsquare: 0.998712965772009
           dfe: 18
    adjrsquare: 0.998569961968899
          rmse: 2.97236624011533


o = 

        numobs: 21
      numparam: 3
     residuals: [21x1 double]
      Jacobian: [21x3 double]
      exitflag: 1
     algorithm: 'QR factorization and solve'
    iterations: 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top