如何在lm上使用lm.fit [英] How to use lm.fit instead on lm

查看:231
本文介绍了如何在lm上使用lm.fit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用lm.fit来提高速度,但是第二版给出了NAs

I want to use lm.fit for speed, but second version gives NAs

 sum <-   summary(lm(y~x))
 slope <-  sum$coefficients[2]

 sum <-   lm.fit(as.matrix(x,ncol=1),y)
 slope <-  sum$coefficients[2]

编辑1

我现在看到sum $ coefficients只有1个值.为什么会这样呢?帮助没有解释这一点

I now see that sum$coefficients only has 1 value. Why is that and what is it? The help doesn't explain this

推荐答案

使用可重现的示例会更容易.

It would be easier to help with a reproducible example.

但是,我的猜测是在第二种情况下您缺少拦截.尝试lm.fit(cbind(1,x),y),看看是否能为您提供所需的比较.

However, my guess is that you are missing an intercept in the second case. Try lm.fit(cbind(1,x),y) and see if that gives you the comparison that you are looking for.

其他差异可能是由于lm在调用lm.fit之前进行的其他预处理引起的,但是我们不知道x就不知道那是什么.诸如删除缺失值,将因子扩展为虚拟变量之类的事情也可能导致差异.

Other differences could be due to the other preprocessing that lm does before calling lm.fit, but we don't know what that is without seeing x. Things like removing missing values, expanding a factor into dummy variables could also result in differences.

这篇关于如何在lm上使用lm.fit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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