Rcpparmadillo:将 fastLM 对象转换为“lm"类型 [英] Rcpparmadillo : Convert fastLM object to type 'lm'

查看:43
本文介绍了Rcpparmadillo:将 fastLM 对象转换为“lm"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先感谢这么好的包裹.我希望在 fastLM 的输出上运行 anova,但是 anova 只接受lm"类型的对象.有没有办法将 fastLM 对象转换为lm"对象?

First of all thanks for such a nice package. I was looking to run anova on the output of fastLM, however anova only accepts objects of type 'lm'. Is there a way to convert a fastLM object to an 'lm' object?

谢谢,

推荐答案

首先,fastLM() 的存在是为了提供比 lm() 更快的东西.

First off, fastLM() exists to provide something faster than lm().

使其更快的方法之一是在返回的对象中提供比 lm() 少得多的信息:

One of the ways to make it faster is to provide a lot less information in the returned object than lm() does:

R> object.size(fitlm <- lm(Girth ~ Volume + Height, data=trees))
22960 bytes
R> library(RcppArmadillo)
R> object.size(fitFastLm <- fastLm(Girth ~ Volume + Height, data=trees))
4264 bytes
R> 

这表明对于来自树数据集的(小而琐碎的)示例,我们返回 4.2 kB 而 lm() 返回 23 kb.因此,我选择不将返回的对象子类化为 lm() 类——因为我们不包含完整的对象.

That shows that for the (small, trivial) example from the trees data set, we return 4.2 kB whereas lm() returns 23kb. Hence I chose not to subclass the returned object as being of class lm() -- as we don't include a full object.

所以 anova() 可能会失败.最简单的方法可能是提取实际的 anova 代码并提供合适的方法,因为我们确实提供了一些分析:

So anova() may fail. The easiest would probably be to factor out actual anova code and provide a suitable method as we do provide some analytics:

R> summary(fitFastLm <- fastLm(Girth ~ Volume + Height, data=trees))

Call:
fastLm.formula(formula = Girth ~ Volume + Height, data = trees)

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-1.342900 -0.566960 -0.086282  0.802830  1.116400 

            Estimate   StdErr t.value  p.value    
(Intercept) 10.81637  1.97320   5.482 7.45e-06 ***
Volume       0.19518  0.01096  17.816  < 2e-16 ***
Height      -0.04548  0.02826  -1.609    0.119    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.79 on 28 degrees of freedom
Multiple R-squared: 0.941,  Adjusted R-squared: 0.937
R> 

如果你想在此基础上提供方差分析,我可以考虑一个写得很好的补丁.

If you want to work on providing anova analysis based on this, I could consider a well-written patch.

这篇关于Rcpparmadillo:将 fastLM 对象转换为“lm"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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