R 从aov中提取p值

R 从aov中提取p值,r,anova,R,Anova,我希望从R中的方差分析中提取p值 以下是我正在运行的内容: test <- aov(asq[,9] ~ asq[,187]) summary(test) 当我观察结构时,这就是我所看到的。我通常可以通过列表来获得我需要的东西,但是我很难找到这个。谷歌搜索的结果似乎也显示了比我得到的要简单得多的结构 注意:ASQ是我的数据帧 str(test) List of 13 $ coefficients : Named num [1:2] 0.2862 0.0973 ..- attr(*,

我希望从R中的方差分析中提取p值

以下是我正在运行的内容:

test <- aov(asq[,9] ~ asq[,187])
summary(test)
当我观察结构时,这就是我所看到的。我通常可以通过列表来获得我需要的东西,但是我很难找到这个。谷歌搜索的结果似乎也显示了比我得到的要简单得多的结构

注意: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"
str(测试)
13人名单
$coverties:Named num[1:2]0.2862 0.0973
..-attr(*,“name”)=chr[1:2](截取)““asq[187]”
$residuals:Named num[1:1337]0.519 0.519-0.481-0.481-0.481。。。
..-attr(*,“name”)=chr[1:1337]“1”2“3”4”。。。
$effects:Named num[1:1337]-16.19-1.738-0.505-0.505-0.505。。。
..-attr(*,“name”)=chr[1:1337]“(截取)”“asq[,187]”。。。
$rank:int 2
$fitted.values:Named num[1:1337]0.481 0.481 0.481 0.481 0.481。。。
..-attr(*,“name”)=chr[1:1337]“1”2“3”4”。。。
$assign:int[1:2]0 1
$qr:5人名单
..$qr:num[1:1337,1:2]-36.5650.0273 0.0273 0.0273 0.0273 0.0273。。。
.. ..- 属性(*,“dimnames”)=2个列表
.. .. ..$ : chr[1:1337]“1”“2”“3”“4”。。。
.. .. ..$ : chr[1:2]“(截取)”“asq[187]”
.. ..- 属性(*,“赋值”)=int[1:2]01
..$qraux:num[1:2]1.03 1.02
..$pivot:int[1:2]12
..$tol:编号1e-07
..$rank:int 2
..-attr(*,“类”)=chr“qr”
$df.剩余:1335内特
$na.action:名为int[1:12]2625735245850862482087410461082的类“省略”。。。
.. ..- 属性(*,“名称”)=chr[1:12]“26”“257”“352”“458”。。。
$xlevels:list()
$call:language aov(公式=asq[,9]~asq[,187])
$terms:class'terms','formula'长度3 asq[,9]~asq[,187]
.. ..- attr(*,“变量”)=语言列表(asq[,9],asq[,187])
.. ..- 属性(*,“因子”)=int[1:2,1]01
.. .. ..- 属性(*,“dimnames”)=2个列表
.. .. .. ..$ : chr[1:2]“asq[,9]”“asq[,187]”
.. .. .. ..$ : chr“asq[187]”
.. ..- attr(*,“术语标签”)=chr“asq[,187]”
.. ..- 属性(*,“顺序”)=整数1
.. ..- 属性(*,“截距”)=整数1
.. ..- 属性(*,“响应”)=int 1
.. ..- 属性(*,“.Environment”)=
.. ..- attr(*,“predvars”)=语言列表(asq[,9],asq[,187])
.. ..- attr(*,“数据类”)=命名的chr[1:2]“数值”“数值”
.. .. ..- attr(*,“名称”)=chr[1:2]“asq[,9]”“asq[,187]”
$model:'data.frame':1337 obs。共有2个变量:
..$asq[,9]:int[1:1337]10100。。。
..$asq[187]:int[1:1337]2。。。
..-attr(*,“术语”)=类“术语”,“公式”长度3 asq[,9]~asq[,187]
.. .. ..- attr(*,“变量”)=语言列表(asq[,9],asq[,187])
.. .. ..- 属性(*,“因子”)=int[1:2,1]01
.. .. .. ..- 属性(*,“dimnames”)=2个列表
.. .. .. .. ..$ : chr[1:2]“asq[,9]”“asq[,187]”
.. .. .. .. ..$ : chr“asq[187]”
.. .. ..- attr(*,“术语标签”)=chr“asq[,187]”
.. .. ..- 属性(*,“顺序”)=整数1
.. .. ..- 属性(*,“截距”)=整数1
.. .. ..- 属性(*,“响应”)=int 1
.. .. ..- 属性(*,“.Environment”)=
.. .. ..- attr(*,“predvars”)=语言列表(asq[,9],asq[,187])
.. .. ..- attr(*,“数据类”)=命名的chr[1:2]“数值”“数值”
.. .. .. ..- attr(*,“名称”)=chr[1:2]“asq[,9]”“asq[,187]”
..-attr(*,“na.action”)=名为int[1:12]26257352458508624820 874 10461082的类“省略”。。。
.. .. ..- 属性(*,“名称”)=chr[1:12]“26”“257”“352”“458”。。。
-属性(*,“类”)=chr[1:2]“aov”lm

查看
str(摘要(测试))
-这就是你看到p值的地方。

我知道这是一个很老的问题,但我在网上四处查看,没有找到解释或一般解决方案,这个线程是谷歌搜索中出现的第一个问题

summary(test)[[1]][["Pr(>F)"]]
Aniko是对的,最简单的方法是查看
摘要(测试)

在重复测量中,它是相似的,但您也可以使用命名项,如

myModelSummary$'Error: subject:A'[[1]]$'Pr(>F)'

注意,我仍然必须进行列表选择,因为重复测量模型中的每个列表项都是1的列表。

由于上面的建议对我不起作用,因此我设法解决了这个问题:

sum_test = unlist(summary(test))
然后用眼睛看着这些名字

names(sum_test)
我有“Pr(>F)1”和“Pr(>F)2”,当第一个值是请求的值时,所以

sum_test["Pr(>F)1"]

将给出比BurningLeo中要求的值略短的值:


2和9是myAOV模型中p值的位置

执行str(测试)时,它列出aov对象的结构。您需要查看的是print.aov()的输出(请参阅方法(print))!Aniko的str(summary(test))就是这么做的。我需要另一个[[1]]]-但是,嘿,这很酷:)
summary(test)[[1][[Pr(>F)”]][[1]]]
如果没有BurninLeo的额外[[1]],它会给出汇总表的最后一列,第二行是空的——我们只希望第一行得到p值,这就是额外的[[1]]是的。如果您不喜欢键入概率陈述,类似的选择是
summary(test)[[1]][1,5]
。但是你可能不想要p值,也想要F统计,所以这将是
summary(test)[[1]][1,4:5]
Hi,我使用了permuco软件包,它的输出与aov的输出类似。但是总结(测试)[[1]][[Pr(>F)]]返回NAWOW,太棒了!!!我已经能够从其他方法中获得p值,但我从未见过“unlist”命令,这将生成一个完整aov输出的优化列表
sum_test = unlist(summary(test))
names(sum_test)
sum_test["Pr(>F)1"]
summary(test)[[1]][[1,"Pr(>F)"]]
summary(aov(y~factor(x)))[[1]][[5]][1]
unlist(summary(myAOV)[[2]])[[9]]