Isolate the significance column from the resume (aov ()) in r

How can I highlight the significance column in the summary (aov ()) by taking the predefined warpbreaks data as an example ...

 > a<-summary(aov(breaks~wool*tension,data=warpbreaks)) > a Df Sum Sq Mean Sq F value Pr(>F) wool 1 451 450.7 3.765 0.058213 . tension 2 2034 1017.1 8.498 0.000693 *** wool:tension 2 1003 501.4 4.189 0.021044 * Residuals 48 5745 119.7 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > somefunction(a)[,6] 1 . 2 *** 3 * 4 
+4
source share
3 answers
 # Extract the p-values pvals <- a[[1]][["Pr(>F)"]] # Use the symnum function to produce the symbols sigSymbols <- symnum(pvals, na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " ")) 

Returns a vector with the attribute:

 > sigSymbols [1] . *** * attr(,"legend") [1] 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

If you don't need the legend attribute, you can use the legend = FALSE argument in the symnum function.

+5
source

I could not find / think of a direct method, so I just created my own. I retrieve the last column of the data frame, i.e. Pr(>F)

 p = a[[1]][,5] 

flushes the last value from this space:

 p = p[-length(p)] 

then worked out the encoding:

 stars = findInterval(p, c(0, 0.001, 0.01, 0.05, 0.1,)) codes = c("***" , "**","*", ".", " ") codes[stars] 

You can, of course, put this in a function if you want.

  get_stars = function(p) {    stars = findInterval(p, c(0, 0.001, 0.01, 0.05, 0.1))    codes = c("***" , "**","*", ".", " ")    codes[stars]  } 

Example

 R> p = c(0.0005, 0.005, 0.025, 0.075, 0.5) R> get_stars(p) [1] "***" "**" "*" "." " " 
+3
source

The methods for extracting the p value described above did not work for me because my model included an error. I had success using the following:

 test.summary <- summary(aov(dv ~ iv1 + Error(grouping.factor / iv1 ), data = df)) p <- test.summary[[2]][[1]][["Pr(>F)"]][1] 

Adding [1] after [["Pr(>F)"]] retrieves only the p value, not the null value after it.

Also, @csgillespie, your code includes an extra comma after the end element in the vector, so R expects an argument after 0.1 :

 stars = findInterval(p, c(0, 0.001, 0.01, 0.05, 0.1,)) 
0
source

All Articles