Ale*_*lex 4 attributes r anova
假设我使用了两种嵌套随机效应模型,anova()结果如下:
new.model: new
current.model: new
Df AIC BIC logLik Chisq Chi Df Pr(>Chisq)
new.model 8 299196 299259 -149590
current.model 9 299083 299154 -149533 115.19 1 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Run Code Online (Sandbox Code Playgroud)
我想只使用表格部分(见下文):
Df AIC BIC logLik Chisq Chi Df Pr(>Chisq)
new.model 8 299196 299259 -149590
current.model 9 299083 299154 -149533 115.19 1 < 2.2e-16 ***
Run Code Online (Sandbox Code Playgroud)
我知道我能够通过使用属性(anova.object)$ heading = NULL将标题设置为null来摆脱标题部分(请参阅打击),但我不知道如何摆脱底部:Signif .代码:.....
new.model: new
current.model: new
Run Code Online (Sandbox Code Playgroud)
我至关重要的是不想使用data.frame(见下文),因为它将空白单元格更改为NA
data.frame(anova(new.model, current.model))
Df AIC BIC logLik Chisq Chi.Df Pr..Chisq.
new.model 8 299196.4 299258.9 -149590.2 NA NA NA
current.model 9 299083.2 299153.6 -149532.6 115.1851 1 7.168247e-27
Run Code Online (Sandbox Code Playgroud)
我想知道你们是否知道应对这种情况的方法.
[更新]:我最终使用print.anova编写了一个包装器:
anova.print = function(object, signif.stars = TRUE, heading = TRUE){
if(!heading)
attributes(object)$heading = NULL
print.anova(object, signif.stars = signif.stars)
}
Run Code Online (Sandbox Code Playgroud)
例:
dv = c(rnorm(20), rnorm(20, mean=2), rnorm(20))
iv = factor(rep(letters[1:3], each=20))
anova.object = anova(lm(dv~iv))
Analysis of Variance Table
Response: dv
Df Sum Sq Mean Sq F value Pr(>F)
iv 2 46.360 23.1798 29.534 1.578e-09 ***
Residuals 57 44.737 0.7849
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
anova.print(anova.object, F, F)
Df Sum Sq Mean Sq F value Pr(>F)
iv 2 46.360 23.1798 29.534 1.578e-09
Residuals 57 44.737 0.7849
Run Code Online (Sandbox Code Playgroud)
42-*_*42- 10
编辑:anova有一个printif.stars作为参数的打印方法
anova(new.model, current.model, signif.stars=FALSE)
> x <- anova(lm(hp~mpg+am, data=mtcars))
> print(x, signif.stars=F)
Analysis of Variance Table
Response: hp
Df Sum Sq Mean Sq F value Pr(>F)
mpg 1 87791 87791 54.5403 3.888e-08
am 1 11255 11255 6.9924 0.01307
Residuals 29 46680 1610
Run Code Online (Sandbox Code Playgroud)
前几天我们有一篇关于不显示 NA 的类似帖子。你可以这样做:
x <- as.matrix(anova(new.model, current.model))
print(x, na.print="", quote=FALSE)
Run Code Online (Sandbox Code Playgroud)
使用数据集的更具可重复性的示例mtcars:
x <- as.matrix(anova(lm(hp~mpg+am, data=mtcars)))
print(x, na.print="", quote=FALSE)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2068 次 |
| 最近记录: |