# Re: [R] A possible too old question on significant test of correlation matrix

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Mon 10 Jul 2006 - 22:54:27 EST

On Mon, 2006-07-10 at 12:48 +0100, Gavin Simpson wrote:
> On Mon, 2006-07-10 at 16:22 +0800, Guo Wei-Wei wrote:
> > Hi, Gavin, your program is excellent. Thank you very much!
> >
> > And I have two further questions.
> >
> > 1. Since it is very possible that the data contains missing value and
> > the program will failed against missing values, I have to delete all
> > the cases contained NA. Can it be done pairwisely?
>
> Yes, with a modification to accept and pass on argument "use", e.g.:
>
> data(iris)
> ## copy data
> iris2 <- iris
> ## simulate some missing values in Sepal.Length
> iris2[sample(1:nrow(iris2), 5), 1] <- NA
>
> ## corProb matrix with missing values
> temp <- corProb(iris2[,1:4], use = "pairwise.complete.obs")
>
> See ?cor for the options you can specify for "use". You'll need to paste
> in the functions below for this to work.
>
> > 2. Can the program show t values instead of p values?
>
> Yes - this is R! The function Bill Venables wrote uses F-values, so I
> looked at what cor.test was doing and modified the function to compute
> either t or F values and to return them or their p-values.

Oops, there was a simple error in the print method. Fixed below:

print.corProb <- function(x, digits = getOption("digits"),

```                          quote = FALSE, na.print = "",
justify = "none", ...) {
xx <- format(unclass(round(x, digits = 4)), digits = digits,
justify = justify)
```

if (any(ina <- is.na(x)))
xx[ina] <- na.print
cat("\nCorrelations are shown below the diagonal\n")   if(attr(x, "pval"))
```     cat(paste("P-values of the ", attr(x, "type"),
"-statistics are shown above the diagonal\n\n",
sep = ""))
else
cat(paste(attr(x, "type"),
"-values are shown above the diagonal\n\n",
sep = ""))
```

if(attr(x, "type") == "t") {
hypoth <- switch(attr(x, "hypoth"),
```                     less = "less than 0",
greater = "greater than 0",
two.sided = "not equal to 0")
cat(paste("alternative hypothesis: true correlation is",
hypoth, "\n\n"))
```

}
print.default(xx, quote = quote, ...)
invisible(x)
}
```--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                 [t] +44 (0)20 7679 0522
ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/cv/
London, UK. WC1E 6BT.         [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help