访问或解析R中summary()中的元素 [英] Access or parse elements in summary() in R

查看:93
本文介绍了访问或解析R中summary()中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行以下R命令进行Dunnett的测试并获得摘要.如何访问下面的线性假设的每一行,这是摘要输出的一部分?基本上我不知道摘要的结构.我尝试使用names(),但似乎无法正常工作,因为我看不到任何命名属性来赋予它.

I run the following R commands to make a Dunnett's test and get the summary. How can I access each row of the Linear Hypotheses below, which is part of summary output? Basically I do not know the structure of the summary. I attempted using names() but it seems not working as I do not see any named attribute to give that.

library("multcomp")
Group <- factor(c("A","A","B","B","B","C","C","C","D","D","D","E","E","F","F","F"))
Value <- c(5,5.09901951359278,4.69041575982343,4.58257569495584,4.79583152331272,5,5.09901951359278,4.24264068711928,5.09901951359278,5.19615242270663,4.58257569495584,6.16441400296898,6.85565460040104,7.68114574786861,7.07106781186548,6.48074069840786)
data <- data.frame(Group, Value)

fit <- aov(Value ~ Group, data)
set.seed(20140123)
Dunnet <- glht(fit, linfct=mcp(Group="Dunnett"))
summary(Dunnet)

        Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: Dunnett Contrasts


Fit: aov(formula = Value ~ Group, data = data)

Linear Hypotheses:
       Estimate Std. Error t value Pr(>|t|)   
B - A == 0 -0.35990    0.37009  -0.972  0.76536   
C - A == 0 -0.26896    0.37009  -0.727  0.90012   
D - A == 0 -0.09026    0.37009  -0.244  0.99895   
E - A == 0  1.46052    0.40541   3.603  0.01794 * 
F - A == 0  2.02814    0.37009   5.480  0.00112 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
   (Adjusted p values reported -- single-step method)

推荐答案

@MatthewLundberg开始这么说,尽管我没有找到str(Dunnet)所需的所有值,所以我恢复为str(summary(Dunnet))并找到了它:

@MatthewLundberg started to say it, though I didn't find all of the values you wanted with str(Dunnet), so I reverted to str(summary(Dunnet)) and found it:

str(summary(Dunnet))
## List of 10
##  $ model      :List of 13
##   ...
##  $ linfct     : num [1:5, 1:6] 0 0 0 0 0 1 0 0 0 0 ...
##   ...
##  $ rhs        : num [1:5] 0 0 0 0 0
##  $ coef       : Named num [1:6] 5.0495 -0.3599 -0.269 -0.0903 1.4605 ...
##   ...
##  $ vcov       : num [1:6, 1:6] 0.0822 -0.0822 -0.0822 -0.0822 -0.0822 ...
##   ...
##  $ df         : int 10
##  $ alternative: chr "two.sided"
##  $ type       : chr "Dunnett"
##  $ focus      : chr "Group"
##  $ test       :List of 7
##   ..$ pfunction   :function (type = c("univariate", "adjusted", p.adjust.methods), ...)  
##   ..$ qfunction   :function (conf.level, adjusted = TRUE, ...)  
##   ..$ coefficients: Named num [1:5] -0.3599 -0.269 -0.0903 1.4605 2.0281
##   .. ..- attr(*, "names")= chr [1:5] "B - A" "C - A" "D - A" "E - A" ...
##   ..$ sigma       : Named num [1:5] 0.37 0.37 0.37 0.405 0.37
##   .. ..- attr(*, "names")= chr [1:5] "B - A" "C - A" "D - A" "E - A" ...
##   ..$ tstat       : Named num [1:5] -0.972 -0.727 -0.244 3.603 5.48
##   .. ..- attr(*, "names")= chr [1:5] "B - A" "C - A" "D - A" "E - A" ...
##   ..$ pvalues     : atomic [1:5] 0.7655 0.9001 0.9989 0.0176 0.0011
##   .. ..- attr(*, "error")= num 0.000755
##   ..$ type        : chr "single-step"
##   ..- attr(*, "class")= chr "mtest"
##  - attr(*, "class")= chr [1:2] "summary.glht" "glht"

summary(Dunnet)$test[c('coefficients', 'sigma', 'tstat', 'pvalues')]
## $coefficients
##       B - A       C - A       D - A       E - A       F - A 
## -0.35990210 -0.26895636 -0.09026055  1.46052454  2.02814166 
## 
## $sigma
##     B - A     C - A     D - A     E - A     F - A 
## 0.3700867 0.3700867 0.3700867 0.4054096 0.3700867 
## 
## $tstat
##      B - A      C - A      D - A      E - A      F - A 
## -0.9724806 -0.7267388 -0.2438903  3.6025896  5.4801802 
## 
## $pvalues
## [1] 0.765312271 0.900150707 0.998946706 0.017585149 0.001147749
## attr(,"error")
## [1] 0.0007157397

这篇关于访问或解析R中summary()中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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