[R] display p-values and significance levels

herwig bachmannherwig at hotmail.com
Sat Jan 31 23:28:10 CET 2009


Hi there,

I got a piece of code for the Iris data which allows to display correlation
coefficients for each Iris species in the lower panel (color coded). I would
now like to add e.g. a "*" to show the significance of each correlation next
to the  correlation coefficient. 

Furthermore I would like to make a t.test between the species "setosa" and
"versicolor" for Sepal.length, ..width..... and so on  and display it int
the horizontal panel 

I would appreciate any help,

Herwig

here the code I've got at the moment:

panel.cor <- function(x, y, digits=2, prefix="", splitvar, col.cor, ...)

{
   usr <- par("usr"); on.exit(par(usr))
   par(usr = c(0, 1, 0, 1))
   r <- abs(cor(x, y))
   if(!missing(splitvar)) {
      r <- c(r, abs(sapply(lapply(split(cbind.data.frame(x, y),
splitvar), cor), function(x)x[1,2])))
   }
   txt <- format(c(r, 0.123456789), digits=digits)[1:4]
   txt <- paste(prefix, txt, sep="")
   if(missing(col.cor)) col.cor <- c("black", "red", "green3", "blue")
   for(i in 1:length(txt)) {
      text(0.5, (1/(length(txt)+1))*i, txt[i], col = col.cor[i])
   }
 }

 pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",
     pch = 21, bg = c("red", "green3", "blue")[unclass(iris$Species)],
lower.panel=panel.cor, splitvar=iris$Species)
------------
#here the code I tried to implement to show the significance levels

test <- cor.test(x, y, ,use="complete.obs")
    Signif <- symnum(test$p.value, corr = FALSE, na = FALSE,
                  cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
                  symbols = c("***", "**", "*", ".", " "))
-- 
View this message in context: http://www.nabble.com/display-p-values--and-significance-levels-tp21769056p21769056.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list