- [R使用计算意思算法? [英] What algorithm is R using to calculate mean?
问题描述
我很好奇,想知道是什么算法有r的平均函数使用。有一些参考这个算法?
I am curious to know what algorithm R's mean function uses. Is there some reference to the numerical properties of this algorithm?
我发现下面的C $ C $在summary.c C:do_summary():
I found the following C code in summary.c:do_summary():
case REALSXP:
PROTECT(ans = allocVector(REALSXP, 1));
for (i = 0; i < n; i++) s += REAL(x)[i];
s /= n;
if(R_FINITE((double)s)) {
for (i = 0; i < n; i++) t += (REAL(x)[i] - s);
s += t/n;
}
REAL(ans)[0] = s;
break;
看来做直线上升意思是:
It seems to do a straight up mean:
for (i = 0; i < n; i++) s += REAL(x)[i];
s /= n;
然后,它增加了什么我假定是一个数值修正这似乎是从数据的平均值的平均差:
Then it adds what i assume is a numerical correction which seems to be the mean difference from the mean of the data:
for (i = 0; i < n; i++) t += (REAL(x)[i] - s);
s += t/n;
我一直无法跟踪该算法在任何地方(意思是不是一个伟大的搜索词)。
I haven't been able to track this algorithm down anywhere (mean is not a great search term).
任何帮助将是非常美联社preciated。
Any help would be much appreciated.
推荐答案
我不知道这是什么样的算法,但马丁Maechler提到的西,以应对1979年以 PR#1228 ,这是由布莱恩·里普利在R-2.3.0实现的。我找不到在上市使用的实际算法源$ C $ C或版本控制日志的引用。它在 cov.c
实施了修订37389和 summary.c
在修订37393。
I'm not sure what algorithm this is, but Martin Maechler mentioned the updating method of West, 1979 in response to PR#1228, which was implemented by Brian Ripley in R-2.3.0. I couldn't find a reference in the source code or version control logs that listed the actual algorithm used. It was implemented in cov.c
in revision 37389 and in summary.c
in revision 37393.
这篇关于 - [R使用计算意思算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!