2

I have this R code

As = rnorm(5, mean = 0, sd = 5)
Bs = rnorm(5, mean = 0, sd = 5)
Cs = rnorm(5, mean = 0, sd = 5)

dat = data.frame(factor   = c("A","A","A","A","A","B","B","B","B","B", 
                              "C","C","C","C","C"),
                 response = c(As, Bs, Cs))

summary(aov(response ~ factor, data = dat))

That return this result

> summary(aov(response ~ factor, data = dat))
            Df Sum Sq Mean Sq F value Pr(>F)
factor       2  36.08   18.04   0.807  0.469
Residuals   12 268.22   22.

I would like to access to the value Pr(>F) that is 0.469. How can I do that?

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Donbeo
  • 17,067
  • 37
  • 114
  • 188
  • 3
    Does this answer your question? [Extract p-value from aov](https://stackoverflow.com/questions/3366506/extract-p-value-from-aov) – Vincent Labatut Dec 11 '20 at 16:21

2 Answers2

5

If you take a look at the structrure of your result (see ?str function) you'll realize about how to use indexing operator ([) in order to get Pr(>F).

> str(result)
List of 1
 $ :Classes ‘anova’ and 'data.frame':   2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 12
  ..$ Sum Sq : num [1:2] 35.7 261.3
  ..$ Mean Sq: num [1:2] 17.9 21.8
  ..$ F value: num [1:2] 0.82 NA
  ..$ Pr(>F) : num [1:2] 0.464 NA
 - attr(*, "class")= chr [1:2] "summary.aov" "listof"

You can do it this way

> result[[1]][["Pr(>F)"]][1]
[1] 0.4636054

or

> result[[1]][[5]][1]
[1] 0.4636054
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • 1
    yall could mention `str` so OP isn't trying to guess how you got those variable names and indices – rawr Mar 21 '14 at 14:52
3
s<-summary(aov(response ~ factor, data = dat))
unlist(s)['Pr(>F)1']

Pr(>F)1 
0.1125695 
tcash21
  • 4,880
  • 4
  • 32
  • 39