我一直在努力。简而言之,我找不到 Excel 用于 R 2的方程式。
这是我的数据:
x:1 2 3 4 5 6 7 8 9 10
y:4 9 1 2 1 1 8 5 5 1我绘制数据,拟合幂律函数(“添加趋势线”)并使用“添加趋势线 > 选项 > 在图表上显示 R 平方值”
显示值:
R 2 = 0.03008。
问题 1
如果我使用'RSQ()'函数在excel中计算它(取Excel为拟合函数找到的参数值),或者使用定义(维基百科)手动计算...
R 2 = 0.0272
问题 2
在 Matlab 中,使用 'fit' 函数,拟合函数的参数(当然还有 R 2)不是 EXCEL 找到的参数。
问题:
所以这是我的主要问题:
Excel 如何计算“添加趋势线”函数中的 R 2,因为它显然不是定义中的那个(维基百科)?
还有一个额外的问题:
为什么 Excel 和 Matlab 的拟合参数不一样?
多谢!
%%%%%% 下面编辑!%%%%
作为对评论的回答;这是我使用的 Matlab 代码:
%% R-squared with the fit function
% use the fit function in Matlab, yobs being the data
[param, results] = fit(x,yobs,'power1');
% R-squared from the fit function :
r_sq_from_fit = results.rsquare;
%% here I calculate "by hand" the R-squared, from the general definition (wikipedia!)
% calculates the fitting data yfit
yfit = (p_powerlaw.a).*x.^p_powerlaw.b;
% mean of the yobs, total sum of squares, and residual sum of squares
yobs_mean = mean(yobs);
SStot = sum((yobs-yobs_mean).^2);
SSres = sum((yobs-yfit).^2);
r_sq_hand = 1-SSres/SStot;
无论我从 Matlab 中的函数获得 R 平方fit
还是“手动”计算它,我都能找到相同的值。Matlab 似乎是一致的,并且显然在其函数中使用了 R-squared 的严格定义......
然而;当我比较时:
RSQ()
Excel 从函数给出的 R 平方值- 以及我通过从定义中手动计算 R 平方获得的值(当然取 Excel 返回给我的yfit值,而不是 Matlab 返回的值,因为 Excel 和 Matlab 不同意拟合参数!)
...我获得不同的价值!Excel:0.027,正如我之前所说,手工计算:-0.1109(!)