cor() 函数是如何加速的?
有点偏离主题的问题,但我想知道是否有人可以告诉我 cor() 函数最近何时以及如何改进?它比我记忆中的要快得多,现在的速度与 HMisc 包中的 rcorr 函数相当,这是我用于大型矩阵的替代相关函数。
感谢所有的建议: 经过一番调查,速度差异是由于使用 use="pairwise" 标志而不是算法更改造成的。使用此选项时,速度差异约为 8 倍。
R 版本 2.4 - 2.13 中 cor() 的速度是相当的。
谢谢,
伊恩
Slightly off-topic question, but I was wondering if anybody could tell me when and how the cor() function was improved recently? It is much, much faster than I remember and is now comparable in speed to the rcorr function in HMisc package, which was my alternative correlation function for large matrices.
Thanks for all the suggestions:
After some investigation, the difference in speed is due to using the use="pairwise" flag rather than an algorithmic change. There is ~8 fold difference in speed difference when using this option.
The speed for cor() on R from version 2.4 - 2.13 is comparable.
Thanks,
Iain
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://cran.r-project.org/src/base/NEWS.html 对最近的变化进行了高度总结,并解释了它们的相关性。有时,这对于获取其他函数中可能影响您正在执行的操作的相关更改很有用。然而,快速查找
cor()
仅显示了一些内容:2.13.0
cor() 和 cov() 的排名相关方法(使用 use = "complete.obs" 计算之前的排名)删除缺失值,而文档暗示首先删除不完整的情况。 (https://bugs.R-project.org/bugzilla3/show_bug.cgi?id=14488PR#14488)
2.11.0
cor() 和 cov() 现在测试非数字参数的误用,例如非错误报告 https://bugs.R-project.org/bugzilla3/show_bug.cgi?id=14207PR#14207。
http://cran.r-project.org/src/base/NEWS.html has a high level summary of recent changes, and explanations of their relevance. This is sometimes useful to pick up related changes in other functions that might affect what you're doing. A quick find for
cor()
only shows a couple things, however:2.13.0
The rank-correlation methods for cor() and cov() with use = "complete.obs" computed the ranks before removing missing values, whereas the documentation implied incomplete cases were removed first. (https://bugs.R-project.org/bugzilla3/show_bug.cgi?id=14488PR#14488)
2.11.0
cor() and cov() now test for misuse with non-numeric arguments, such as the non-bug report https://bugs.R-project.org/bugzilla3/show_bug.cgi?id=14207PR#14207.
在不知道您正在运行的版本的情况下很难说,但看起来 2.14 中出现了一些实质性的变化,并且 2.13 和以前的版本之间只有微小的变化,至少回到 2.10。比较这些以查看 2.14: 2.13 代码中的当前更改
:
https://svn.r -project.org/R/branches/R-2-13-branch/src/main/cov.c
2.14代码:
https://svn.r -project.org/R/branches/R-2-14-branch/src/main/cov.c
Hard to say without knowing what version you're running, but it looks like there are some substantial changes coming in 2.14, and only minor changes between 2.13 and previous versions back to at least 2.10. Compare these to see the current changes coming in 2.14:
2.13 code:
https://svn.r-project.org/R/branches/R-2-13-branch/src/main/cov.c
2.14 code:
https://svn.r-project.org/R/branches/R-2-14-branch/src/main/cov.c