c - What algorithm is R using to calculate mean? -
i curious know algorithm r's mean function uses. there reference numerical properties of algorithm?
i found following c code in summary.c:do_summary():
case realsxp: protect(ans = allocvector(realsxp, 1)); (i = 0; < n; i++) s += real(x)[i]; s /= n; if(r_finite((double)s)) { (i = 0; < n; i++) t += (real(x)[i] - s); s += t/n; } real(ans)[0] = s; break;
it seems straight mean:
for (i = 0; < n; i++) s += real(x)[i]; s /= n;
then adds assume numerical correction seems mean difference mean of data:
for (i = 0; < n; i++) t += (real(x)[i] - s); s += t/n;
i haven't been able track algorithm down anywhere (mean not great search term).
any appreciated.
i'm not sure algorithm is, martin maechler mentioned updating method of west, 1979 in response pr#1228, implemented brian ripley in r-2.3.0. couldn't find reference in source code or version control logs listed actual algorithm used. implemented in cov.c
in revision 37389 , in summary.c
in revision 37393.
Comments
Post a Comment