##### Personal tools
You are here: Home R functions to put confidence interval on d'

# R functions to put confidence interval on d'

R functions to put a confidence interval on d'

boot.d.ci(x,y,ci=0.95,b=1000,abs=F,na.rm=F)

Where x and y are the groups to be compared, ci defaults to 0.95, and b (the number of resamplings defaults to 1000). I hope the rest is obvious.

(will try attaching file, failed due to lack of permissions last time)

------------------------------

# Bootstrap a confidence interval on d' - Pete Hurd 23 June 2009

# This uses Cohen's (1988) p44 pooled variance method.
get.d <- function(x,y,absolute=T){
diff <- mean(x,na.rm=T)-mean(y,na.rm=T)
if (absolute) diff <- abs(diff)
S <- sqrt((sd(x,na.rm=T)^2+sd(y,na.rm=T)^2)/2)
d <- diff/S
return(d)
}

# revised version 23 June 2009 - make na.rm=F & abs=F defaults
boot.d.ci <- function(x,y,ci=0.95,b=1000,abs=F,na.rm=F){
if (na.rm){
x <- x[!is.na(x)]
y <- y[!is.na(y)]
}
a <- (1-ci)/2
boots <- numeric(length=0)
for (i in 1:b){
boots <- c(boots,get.d(sample(x,replace=T),sample(y,replace=T),absolute=abs))
}
return(quantile(boots,c(a,1-a)))
}

--------------------------------------

##### Document Actions 