69

Rのanovaから生成された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

構造を見ると、これが見えます。私は通常、必要なものを取得するためにリストを操作できますが、これには苦労しています. Google で検索したところ、私が得ているよりもはるかに単純な構造が明らかになったようです。

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

7 に答える 7

89

ここ:

summary(test)[[1]][["Pr(>F)"]][1]
于 2010-07-29T22:12:38.023 に答える
21

上記の提案がうまくいかなかったので、これが私がそれを解決する方法です:

sum_test = unlist(summary(test))

次に、名前を見て

names(sum_test)

私は "Pr(>F)1" と "Pr(>F)2" を持っています。最初は要求された値なので、

sum_test["Pr(>F)1"]

要求された値を提供します

于 2014-04-29T13:26:34.383 に答える
9

これが古いことは知っていますが、オンラインで調べたところ、説明や一般的な解決策が見つかりませんでした。このスレッドは、Google 検索で最初に表示されるものの 1 つです。

Aniko そうです、最も簡単な方法は を調べることですsummary(test)

tests <- summary(test)
str(tests)

これにより、独立したメジャー aov オブジェクトの 1 のリストが得られますが、メジャーが繰り返される複数のアイテムを持つ可能性があります。反復測定では、リスト内の各項目は、リスト内の項目の誤差項によって定義されます。多くの新しい人が混乱するのは、小節の間にある場合、1 つのリスト項目に名前が付けられていないことです。そのため、彼らは実際にはそれに気付かず、一般的なセレクターを使用してもうまくいかない理由を理解していません。

独立した対策の場合、次のようなものが機能します。

tests[[1]]$'Pr(>F)'

繰り返し測定しても似ていますが、次のような名前付きアイテムを使用することもできます...

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

繰り返し測定モデルのリスト項目のそれぞれが再び 1 のリストであるため、リストの選択を行う必要があったことに注意してください。

于 2012-04-13T17:53:46.473 に答える
5

チェックアウトstr(summary(test))- ここに p 値が表示されます。

于 2010-07-29T20:34:20.653 に答える
3

BurningLeo のアドバイスよりもやや短い:

summary(test)[[1]][[1,"Pr(>F)"]]
于 2014-06-17T07:47:17.490 に答える
2
summary(aov(y~factor(x)))[[1]][[5]][1]
于 2016-03-02T06:16:16.997 に答える