是否有更快的lm功能 [英] Is there a faster lm function

查看:104
本文介绍了是否有更快的lm功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为1M个单独的数据集(data.frame为1M * 50行,或数组为1M * 50)获得线性回归拟合的斜率.现在,我正在使用lm()函数,该函数需要很长时间(大约10分钟).

I would like to get the slope of a linear regression fit for 1M separate data sets (1M * 50 rows for data.frame, or 1M * 50 for array). Now I am using the lm() function, which takes a very long time (about 10 min).

线性回归有更快的功能吗?

Is there any faster function for linear regression?

推荐答案

是的:

  • R本身具有lm.fit(),这更是准系统:没有公式符号,结果集更简单

  • R itself has lm.fit() which is more bare-bones: no formula notation, much simpler result set

与我们有关的 Rcpp 相关的软件包中有fastLm()个实现:RcppArmadillo,RcppEigen,RcppGSL .

several of our Rcpp-related packages have fastLm() implementations: RcppArmadillo, RcppEigen, RcppGSL.

我们已经在许多博客文章和演示中描述了fastLm().如果您想以最快的方式使用它,请不要使用公式界面:解析公式和准备模型矩阵要比实际回归花费更多时间.

We have described fastLm() in a number of blog posts and presentations. If you want it in the fastest way, do not use the formula interface: parsing the formula and preparing the model matrix takes more time than the actual regression.

也就是说,如果在单个向量上回归单个向量,则可以简化此步骤,因为不需要矩阵包.

That said, if you are regressing a single vector on a single vector you can simplify this as no matrix package is needed.

这篇关于是否有更快的lm功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆