conf.med <- function(x) {
# Luc Wouters (wouters@janbe.jnj.com) sent me
# the following function:
# ----------Message from Luc Wouters-------------------------
# A distribution-free confidence interval on the median assuming only iid
# is based on the order statistics and the binomial distribution. See 
#   Lehmann (Nonparametrics: Statistical Methods Based on Ranks, 
#   Holden-Day, 1975, p.182-183). 
# The following S-Plus function can be used to set up such a 95%
# distribution-free confidence interval on the median:
	v <- sort(x, na.last = NA)
	n <- length(x)
	if(n > 0) {
		m <- median(x)
		i <- qbinom(0.025, n, 0.5)
		if(i > 0)
			r <- c(m, v[i], v[n - i + 1])
		else r <- c(m, NA, NA)
	}
	else r <- c(NA, NA, NA)
	r <- as.data.frame(list(median = r[1], lower = r[2], upper = r[3]))
	class(r) <- "table"
	r
}

#conf.med(na.omit(bdi1$CORE14A))
tmp <- read.table("d:\\Data\\TCs\\ATC_Quality_Assurance_Panel\\Data3\\SP2000\\BDI1CORE14A.txt",as.is=TRUE)
conf.med(na.omit(tmp$V1))
