r - 在 R 中访问或解析 summary() 中的元素

标签 r statistics output elements

我运行以下 R 命令来进行 Dunnett 检验并获取摘要。如何访问下面线性假设的每一行,这是摘要输出的一部分?基本上我不知道摘要的结构。我尝试使用 names() 但它似乎不起作用,因为我没有看到任何命名属性来提供它。

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)) 并找到了它:

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 - 在 R 中访问或解析 summary() 中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25225480/

相关文章:

mysql - R中的序列化对象到mysql数据库

r - Shiny 中带有 htmltools 的 dygraphs 列表

r - 当 R 中的卡方检验生成警告时,如何执行 Fisher 精确检验 `fisher.test()`?

python - 尝试构建一个程序来组织安全数据并将其显示在图表中

ubuntu - 从文件中删除所有非 utf-8 字符,终端中没有输出

python - Modelica - Dymola Python 接口(interface) : Set output format to textual

R 编程 - 字符串转换为数字

r - 如何从R中的向量创建边缘列表

algorithm - 多维空间的归一化,这是什么算法?

c - "Freezing"控制台中的输入行并打印在上面的行上?