R/scorci.R

scorci <-
function(x,y,nboot=1000,alpha=.05,SEED=TRUE,plotit=TRUE,STAND=TRUE,corfun=pcor,cop=3,...){
#
#   Compute a .95 confidence interval for the skipped correlation.
#   By default, Pearson's correlation is computed after outliers are removed via the R function outdoor
#   corfun=spear, for example would replace Pearson's correlation with Spearman's correlation.
#
#   The default number of bootstrap samples is nboot=1000
#
if(ncol(as.matrix(x))!=1)stop('x should be a single vector')
m1=cbind(x,y)
m1<-elimna(m1)  # Eliminate rows with missing values
nval=nrow(m1)
x<-m1[,1]
y<-m1[,2]
est<-scor(x,y,plotit=plotit,STAND=STAND,corfun=corfun,SEED=TRUE,cop=cop,...)$cor
if(SEED)set.seed(2) # set seed of random number generator so that
#             results can be duplicated.
#
data<-matrix(sample(length(y),size=length(y)*nboot,replace=TRUE),nrow=nboot)
data=listm(t(data))
bvec<-lapply(data,scorsubMC,x,y,STAND=STAND,corfun=corfun,cop=cop,...) 
bvec=matl(bvec)   # A 1 by nboot matrix.
bvec=as.vector(bvec)
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)
}
musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.