[R] Cuzick's test for trend

andrewejaffe andrewejaffe at gmail.com
Fri Dec 23 18:55:20 CET 2011

```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)
> cuzick(x,z,"two.sided")
Z      p  testType
1 2.11 0.0348 two.sided
</code>

arin basu-2 wrote
>
> Hi All:
>
> I was looking for, but could not locate in the packages, or in the R
> archive searches if there exists an R implementation of Cuzick's test of
> trend. The test is described as follows:
>
> An extension of the Wilcoxon rank-sum test is developed to handle the
> situation in which a variable is measured for individuals in three or more
> (ordered) groups and a non-parametric test for trend across these groups
> is desired.
>
> Reference:
>
> Cuzick J. A Wilcoxon-type test for trend. Stat Med. 1985
> Jan-Mar;4(1):87-90
>
> Would greatly appreciate your insights. The R version I use is R-2.3.1
>
> Best,
> Arin Basu
>
> ______________________________________________
> R-help at .ethz mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help