我希望提取R中的anova生成的p值.
这是我正在运行的:
test <- aov(asq[,9] ~ asq[,187])
summary(test)
Run Code Online (Sandbox Code Playgroud)
产量:
Df Sum Sq Mean Sq F value Pr(>F)
asq[, 187] 1 3.02 3.01951 12.333 0.0004599 ***
Residuals 1335 326.85 0.24483
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
12 observations deleted due to missingness
Run Code Online (Sandbox Code Playgroud)
当我看到结构时,这就是我所看到的.我通常可以通过列表来获得我需要的东西,但是我很难用这个.谷歌搜索也似乎揭示了比我更简单的结构.
注意:ASQ是我的数据框架.
str(test)
List of 13
$ coefficients : Named num [1:2] 0.2862 0.0973
..- attr(*, "names")= chr [1:2] "(Intercept)" "asq[, 187]"
$ residuals : Named num [1:1337] 0.519 0.519 -0.481 -0.481 -0.481 ...
..- attr(*, "names")= chr [1:1337] "1" "2" "3" "4" ...
$ effects : Named num [1:1337] -16.19 -1.738 -0.505 -0.505 -0.505 ...
..- attr(*, "names")= chr [1:1337] "(Intercept)" "asq[, 187]" "" "" ...
$ rank : int 2
$ fitted.values: Named num [1:1337] 0.481 0.481 0.481 0.481 0.481 ...
..- attr(*, "names")= chr [1:1337] "1" "2" "3" "4" ...
$ assign : int [1:2] 0 1
$ qr :List of 5
..$ qr : num [1:1337, 1:2] -36.565 0.0273 0.0273 0.0273 0.0273 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:1337] "1" "2" "3" "4" ...
.. .. ..$ : chr [1:2] "(Intercept)" "asq[, 187]"
.. ..- attr(*, "assign")= int [1:2] 0 1
..$ qraux: num [1:2] 1.03 1.02
..$ pivot: int [1:2] 1 2
..$ tol : num 1e-07
..$ rank : int 2
..- attr(*, "class")= chr "qr"
$ df.residual : int 1335
$ na.action :Class 'omit' Named int [1:12] 26 257 352 458 508 624 820 874 1046 1082 ...
.. ..- attr(*, "names")= chr [1:12] "26" "257" "352" "458" ...
$ xlevels : list()
$ call : language aov(formula = asq[, 9] ~ asq[, 187])
$ terms :Classes 'terms', 'formula' length 3 asq[, 9] ~ asq[, 187]
.. ..- attr(*, "variables")= language list(asq[, 9], asq[, 187])
.. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr [1:2] "asq[, 9]" "asq[, 187]"
.. .. .. ..$ : chr "asq[, 187]"
.. ..- attr(*, "term.labels")= chr "asq[, 187]"
.. ..- attr(*, "order")= int 1
.. ..- attr(*, "intercept")= int 1
.. ..- attr(*, "response")= int 1
.. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
.. ..- attr(*, "predvars")= language list(asq[, 9], asq[, 187])
.. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
.. .. ..- attr(*, "names")= chr [1:2] "asq[, 9]" "asq[, 187]"
$ model :'data.frame': 1337 obs. of 2 variables:
..$ asq[, 9] : int [1:1337] 1 1 0 0 0 1 1 1 0 0 ...
..$ asq[, 187]: int [1:1337] 2 2 2 2 2 2 2 2 2 2 ...
..- attr(*, "terms")=Classes 'terms', 'formula' length 3 asq[, 9] ~ asq[, 187]
.. .. ..- attr(*, "variables")= language list(asq[, 9], asq[, 187])
.. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. ..$ : chr [1:2] "asq[, 9]" "asq[, 187]"
.. .. .. .. ..$ : chr "asq[, 187]"
.. .. ..- attr(*, "term.labels")= chr "asq[, 187]"
.. .. ..- attr(*, "order")= int 1
.. .. ..- attr(*, "intercept")= int 1
.. .. ..- attr(*, "response")= int 1
.. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
.. .. ..- attr(*, "predvars")= language list(asq[, 9], asq[, 187])
.. .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
.. .. .. ..- attr(*, "names")= chr [1:2] "asq[, 9]" "asq[, 187]"
..- attr(*, "na.action")=Class 'omit' Named int [1:12] 26 257 352 458 508 624 820 874 1046 1082 ...
.. .. ..- attr(*, "names")= chr [1:12] "26" "257" "352" "458" ...
- attr(*, "class")= chr [1:2] "aov" "lm"
Run Code Online (Sandbox Code Playgroud)
Gre*_*reg 68
summary(test)[[1]][["Pr(>F)"]]
Run Code Online (Sandbox Code Playgroud)
yei*_*orn 19
由于上面的建议对我不起作用,这就是我设法解决它的方法:
sum_test = unlist(summary(test))
Run Code Online (Sandbox Code Playgroud)
然后看着名字
names(sum_test)
Run Code Online (Sandbox Code Playgroud)
我有"Pr(> F)1"和"Pr(> F)2",当第一个它是请求值时,所以
sum_test["Pr(>F)1"]
Run Code Online (Sandbox Code Playgroud)
将提供所要求的价值
我知道这已经过时了但是我在网上看了一下并没有找到解释或一般解决方案,这个帖子是谷歌搜索中出现的第一件事.
Aniko是对的,最简单的方法是查看summary(test).
tests <- summary(test)
str(tests)
Run Code Online (Sandbox Code Playgroud)
这为您提供了一个独立测量aov对象的列表,但它可能有多个重复测量的项目.通过重复测量,列表中的每个项目都由列表中项目的错误术语定义.许多新人感到困惑的地方在于,如果在测量之间,则单个列表项目未命名.因此,他们并没有真正注意到这一点,也不明白为什么使用典型的选择器不起作用.
在独立措施案例中,类似于以下工作.
tests[[1]]$'Pr(>F)'
Run Code Online (Sandbox Code Playgroud)
在重复的措施中它是相似的,但你也可以使用像......这样的命名项目
myModelSummary$'Error: subject:A'[[1]]$'Pr(>F)'
Run Code Online (Sandbox Code Playgroud)
请注意,我仍然必须进行该列表选择,因为重复测量模型中的每个列表项都是1的列表.
| 归档时间: |
|
| 查看次数: |
65386 次 |
| 最近记录: |