我正在使用mathowrks示例计算多项式拟合:
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)');
如何找到这种拟合的相关性?通过简单的线性关系,我可以使用corrcoef来计算拟合,但在mathworks网站上他们只提到“他的下图显示二次多项式拟合提供了对数据的良好近似”,但不进入任何统计。
有人可以推荐一种方法吗?
http://www.mathworks.co.uk/help/matlab/data_analysis/programmatic-fitting.html
答案 0 :(得分:2)
您可以使用以下内容:
ft_ = fittype('poly2');
[cf,gf,o] = fit(cdate,pop,ft_)
当我这样做时,我的结果是:
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