pcorbv4 <-
function(x,y,SEED=TRUE){
# Compute a .95 confidence interval for Pearson's correlation coefficient.
#
# This function uses an adjusted percentile bootstrap method that
# gives good results when the error term is heteroscedastic.
#
# WARNING: If the number of boostrap samples is altered, it is
# unknown how to adjust the confidence interval when n < 250.
# (An obvious guess seems to work well, but no formal investigations
# have been performed.)
#
nboot<-599 #Number of bootstrap samples
if(SEED)set.seed(2) # set seed of random number generator so that
# results can be duplicated.
xy<-elimna(cbind(x,y))
x<-xy[,1]
y<-xy[,2]
#print("Taking bootstrap samples; please wait")
data<-matrix(sample(length(y),size=length(y)*nboot,replace=TRUE),nrow=nboot)
bvec<-apply(data,1,pcorbsub,x,y) # A 1 by nboot matrix.
ilow<-13
ihi<-586
if(length(y) < 250){
ilow<-12
ihi<-587
}
if(length(y) < 180){
ilow<-11
ihi<-588
}
if(length(y) < 80){
ilow<-8
ihi<-592
}
if(length(y) < 40){
ilow<-7
ihi<-593
}
bsort<-sort(bvec)
r<-cor(x,y)
ci<-c(bsort[ilow],bsort[ihi])
list(r=r,ci=ci)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.