Hi Marie,
Here is a function that I wrote based on the "JT.test " function in
package "SAGx", to account for missing values and to order based on
the groups.
JT.fun <- function(y, g) {
nas <- is.na(y) | is.na(g)
ord <- order(g[!nas])
d <- y[!nas][ord]
g <- g[!nas][ord]
return (JT.test(data=t(as.matrix(d)),class=g) )
}
Here is an example showing how to use it:
> library(SAGx)
> y <- rnorm(30, mean=rep( c(0,1,2), ea=10) )
> grp <- rep(1:3, ea=10)
> JT.fun( y , grp)
This will give you a two-sided p-value. If your alternative is one-sided then
you divide this p-value by 2.
Hope this helps,
Ravi.
----- Original Message -----
From: Marie Kraska <kraskmf at auburn.edu>
Date: Saturday, March 25, 2006 12:35 pm
Subject: Re: [R] Jonckheere-Terpstra test
> Hello, Can anyone tell me how to write the R script to get the P-value
> for the Jonckheere-Terpstra (JT) test? Following is the code I am
> using.I cannot get the P-value to print out. Any help would be
> appreciated.Thanks. Marie
>
>
> jt <- function(x, alpha=.05){
> if(is.list(x) == 0) stop("Please enter a list of
vectors.")
> k <- length(x)
> us <- matrix(0,k,k)
> for(i in 1:(k-1)){
> for(j in (i+1):k){
> us[i,j] <- wilcox.test(x[[j]],
> x[[i]])$statistic
> }
> }
> sum(us)
> }
>
>
> con <- c(40,35,38,43,44,41)
> gpb <- c(38,40,47,44,40,42)
> gpc <- c(48,40,45,43,46,44)
>
> jt(list(con,gpb,gpc))
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-
> guide.html