gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:46:52 26 4
gpt4 key购买 nike

我运行以下 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com