How to use lm.fit instead on lm [closed]

試著忘記壹切 提交于 2019-12-23 06:40:08

问题


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

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

or

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

EDIT 1

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


回答1:


It would be easier to help with a reproducible example.

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.

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.



来源:https://stackoverflow.com/questions/16675614/how-to-use-lm-fit-instead-on-lm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!