corbMC <-
function(x,y,corfun=pbcor,nboot=599,alpha=.05,SEED=TRUE,...){
#
# Compute a .95 confidence interval for a correlation.
# The default correlation is the percentage bend.
#
# The function corfun is any R function that returns a
# correlation coefficient in corfun$cor. The functions pbcor and
# wincor follow this convention.
#
# When using Pearson's correlation, and when n<250, use
# lsfitci instead.
#
# The default number of bootstrap samples is nboot=599
#
library(parallel)
m1=cbind(x,y)
m1<-elimna(m1) # Eliminate rows with missing values
nval=nrow(m1)
x<-m1[,1]
y<-m1[,2]
est<-corfun(x,y,...)$cor
if(SEED)set.seed(2) # set seed of random number generator so that
# results can be duplicated.
#
# If you use corfun=scor, set plotit=F
#
data<-matrix(sample(length(y),size=length(y)*nboot,replace=TRUE),nrow=nboot)
data=listm(t(data))
bvec<-mclapply(data,corbsub,x,y,corfun,...)
bvec=matl(bvec) # A 1 by nboot matrix.
ihi<-floor((1-alpha/2)*nboot+.5)
ilow<-floor((alpha/2)*nboot+.5)
bsort<-sort(bvec)
corci<-1
corci[1]<-bsort[ilow]
corci[2]<-bsort[ihi]
phat <- sum(bvec < 0)/nboot
sig <- 2 * min(phat, 1 - phat)
list(cor.ci=corci,p.value=sig,cor.est=est)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.