Skip to content

Cuzick's test for trend

1 message · andrewejaffe

#
I just wrote this up for a project, perhaps 5 years is better than never...

<code>
cuzick = function(x,z,test.type=c("two.sided", "upper", "lower")) {

	N = length(z)
	n = unique(z)

	ranks=rank(x)

	T = sum(ranks*z)

	p = (table(z)/N)
	E_Z = sum(unique(z)*p)
	E_T = 0.5*N*(N+1)*E_Z

	Var_Z = sum(unique(z)^2*p) - E_Z^2
	Var_T = N^2*(N+1)/12*Var_Z

	Zscore = (T-E_T)/sqrt(Var_T)
	
	if(test.type == "two.sided") {
		pval = 2*pnorm(-abs(Zscore))
	} else if(test.type == "upper") {
		pval = pnorm(Zscore,lower.tail=F)
	} else 	pval = pnorm(Zscore,lower.tail=T)

	out = data.frame(cbind(Zscore,pval,test.type))
	colnames(out) = c("Z","p","testType")
	return(out)
}
</code>

With data from the Cuzick 1985 paper:
<code>
z = c(rep(1, 8), rep(2,10), rep(3,9), rep(4,9),rep(5,9))
x = c(0, 0, 1, 1, 2, 2, 4, 9,
		0, 0, 5, 7, 8, 11, 13, 23, 25, 97,
		2, 3, 6, 9, 10, 11, 11, 12, 21,
		0, 3, 5, 6, 10, 19, 56, 100, 132,
		2, 4, 6, 6, 6, 7, 18, 39, 60)
Z      p  testType
1 2.11 0.0348 two.sided
</code>



arin basu-2 wrote
--
View this message in context: http://r.789695.n4.nabble.com/Cuzick-s-test-for-trend-tp807101p4229374.html
Sent from the R help mailing list archive at Nabble.com.