[R-sig-eco] number of observations used in scatterplot.matrix()

Peter Solymos solymos at ualberta.ca
Fri Jan 21 16:34:39 CET 2011


Maria,

You can have number of complete pairs for each column pair combination as

(x <- matrix(c(NA,NA,NA,1,2,3), 2, 3))
(x.na <- !is.na(x))
t(x.na) %*% x.na

You can supply this as is or its lower triangle as vector to the
plotting function.

Cheers,

Peter



On Fri, Jan 21, 2011 at 8:25 AM, Maria Dulce Subida
<mdsubida at icman.csic.es> wrote:
> Hi Luciano,
>
> Thank you for your suggestion. However I'm afraid it will not work,
> since the actual number of observations used by cor.test() is not the
> total number of observations (nrow(x))  I have.
> cor.test() omits observations with NAs in x or in y, which do actually
> occur in my data sets.
>
> Kind regards,
>
> Dulce
>
>
> El 21/01/2011 16:13, Luciano Selzer escribió:
>> Hi, maybe something like this should do the trick:
>>           n <- nrow(x)
>>
>>             txt <- paste("rho=", txt, "\np=",pval, "n=", n, sep="")
>>
>>
>> HTH
>> Luciano
>>
>>
>> 2011/1/21 Maria Dulce Subida <mdsubida at icman.csic.es
>> <mailto:mdsubida at icman.csic.es>>
>>
>>     Dear all,
>>
>>     I have a script (please see below) that gives a scatter plot matrix on
>>     the upper panel, and the spearman rho and probability values on the
>>     lower panel. It also gives the density function of each variable
>>     in the
>>     diagonal, adds a smoother and a linear regression line to each scatter
>>     plot, and puts significant spearman coefficient values in red.
>>     Now I would like to add to the lower panel information, the value of
>>     n=number of observations used to calculate the spearman correlation
>>     coefficient. Does anyone know I could I add that parameter to my
>>     function panel.cor?
>>
>>     Thank you!
>>
>>     Kind regards,
>>
>>     Dulce
>>
>>     ################
>>
>>     panel.cor <- function (x, y,method="spearman",digits=2,...)
>>     {
>>             points(x,y,type="n");
>>             usr <- par("usr"); on.exit(par(usr))
>>             par(usr = c(0, 1, 0, 1));
>>             correl <- cor.test(x, y,method=method);
>>             r=correl$estimate;
>>             pval=correl$p.value;
>>             color="black";
>>             if (pval<0.05) color="red";
>>             txt <- format(r,digits=2)
>>             pval <- format(pval,digits=2)
>>
>>            n <- nrow(x)
>>
>>             txt <- paste("rho=", txt, "\np=",pval, "n=", n, sep="")
>>             text(0.5, 0.5, txt,col=color)
>>     }
>>
>>     scatterplot.matrix (~ var1 + var2 + var3 , data=mydata,
>>                                     main="Mydata", smooth=TRUE,
>>     lower.panel=panel.cor, pch=20, cex=0.5,
>>     col=c("red","black"),cex.labels=1, font.labels=2, lwd=0.5)
>>
>>
>>
>>
>>
>>            [[alternative HTML version deleted]]
>>
>>     _______________________________________________
>>     R-sig-ecology mailing list
>>     R-sig-ecology at r-project.org <mailto:R-sig-ecology at r-project.org>
>>     https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>
>>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>



More information about the R-sig-ecology mailing list