r - 从 aov 中提取 p 值

标签 r anova

我希望提取 R 中方差分析生成的 p 值。

这是我正在运行的内容:

test <- aov(asq[,9] ~ asq[,187])
summary(test)

产量:

              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

当我查看结构时,这就是我所看到的。我通常可以通过列表来获得我需要的东西,但我在这个方面遇到了困难。谷歌搜索似乎也揭示了比我得到的简单得多的结构。

注意: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"

最佳答案

这里:

summary(test)[[1]][["Pr(>F)"]][1]

关于r - 从 aov 中提取 p 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3366506/

相关文章:

R 用于点击光栅图像时进行传单重定向

r - "Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases"做 2-way 重复测量 anova 测试时

r - 使用 anova() 测试 lmer() 模型中的随机效应时,是否需要设置 refit=FALSE?

r - 如何从 R 中的方差分析中获取 rsquare

加法双向表 Tukey 图的 R 实现

R svgPanZoom 自定义大小并添加定位器

基于不同列的 R 数据表 styleColorBar

python - python中的ANOVA使用带有statsmodels或scipy的pandas数据框?

r - 如何在 R Markdown 文档中自动包含文件路径

Python 相当于 R 中的 which()