Skip to content
Prev 168829 / 398506 Next

display p-values and significance levels

herwig wrote:
Not sure if this is homework...
first part of your question is implemented as follows (including some 
other code improvements), just use the same ideas for the t-tests ....


panel.cor <- function(x, y, digits=2, prefix="", splitvar, col.cor, ...)
{
     usr <- par(usr = c(0, 1, 0, 1))
     on.exit(par(usr))
     r <- abs(cor(x, y))
     test <- cor.test(x, y, use="complete.obs")[["p.value"]]
     if(!missing(splitvar)){
         temp <- split(data.frame(x=x, y=y), splitvar)
         r <- c(r, abs(sapply(temp, function(x) cor(x)[1,2])))
         test <- c(test, sapply(temp, function(x) cor.test(x$x, x$y, 
use="complete.obs")[["p.value"]]))
     }
     Signif <- symnum(test, corr = FALSE, na = FALSE,
         cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
         symbols = c("***", "**", "*", ".", " "))
     txt <- format(r, nsmall = digits, digits = digits)
     txt <- paste(prefix, txt, " ", Signif, sep="")
     if(missing(col.cor))
         col.cor <- c("black", "red", "green3", "blue")
     text(0.5, seq_along(txt) / (length(txt)+1), txt, col = col.cor, 
adj=c(0, 0.5))
}

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)

Uwe Ligges