percentCor.R
##copyright R. Gentleman, 2004, all rights reserved
percentCor = function(x, y, percent=25, method="pearson") { if( percent < 0 || percent > 100 ) stop("bad percent") if( percent < 1 ) warning("percent less than one - is that what you meant?")
if( !is.null(dim(x)) && !is.null(dim(y)) ) stop("only vectors, for now, please")
quantx = quantile(x, 1-percent/100) quanty = quantile(y, 1-percent/100)
goodx = x > quantx goody = y > quanty
cor1 = cor(x[goodx], y[goodx], method=method) cor2 = cor(x[goody], y[goody], method=method) return((cor1+cor2)/2) }