Skip to content
Prev 300128 / 398506 Next

significance test interquartile ranges

Hello,

There's a test for iqr equality, of Westenberg (1948), that can be found 
on-line if one really looks. It starts creating a 1 sample pool from the 
two samples and computing the 1st and 3rd quartiles. Then a three column 
table where the rows correspond to the samples is built. The middle 
column is the counts between the quartiles and the side ones to the 
outsides. These columns are collapsed into one and a Fisher exact test 
is conducted on the 2x2 resulting table.

R code could be:


iqr.test <- function(x, y){
	qq <- quantile(c(x, y), prob = c(0.25, 0.75))
	a <- sum(qq[1] < x & x < qq[2])
	b <- length(x) - a
	c <- sum(qq[1] < y & y < qq[2])
	d <- length(y) - b
	m <- matrix(c(a, c, b, d), ncol = 2)
	numer <- sum(lfactorial(c(margin.table(m, 1), margin.table(m, 2))))
	denom <- sum(lfactorial(c(a, b, c, d, sum(m))))
	p.value <- 2*exp(numer - denom)
	data.name <- deparse(substitute(x))
	data.name <- paste(data.name, ", ", deparse(substitute(y)), sep="")
	method <- "Westenberg-Mood test for IQR range equality"
	alternative <- "the IQRs are not equal"
	ht <- list(
		p.value = p.value,
		method = method,
		alternative = alternative,
		data.name = data.name
	)
	class(ht) <- "htest"
	ht
}

n <- 1e3
pv <- numeric(n)
set.seed(2319)
for(i in 1:n){
	x <- rnorm(sample(20:30, 1), 4, 1)
	y <- rchisq(sample(20:40, 1), df=4)
	pv[i] <- iqr.test(x, y)$p.value
}

sum(pv < 0.05)/n  # 0.8


Hope this helps,

Rui Barradas

Em 14-07-2012 09:01, peter dalgaard escreveu: