Re: [R] Jonckheere-Terpstra test

2006-03-25 Thread Marie Kraska
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@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


Re: [R] Jonckheere-Terpstra test

2006-03-25 Thread RAVI VARADHAN
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 [EMAIL PROTECTED]
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@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

__
R-help@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


RE: [R] Jonckheere-Terpstra test

2003-10-06 Thread Kim Mouridsen
The Jonckheere-Terpstra test is a distribution-free test for ordered
alternatives in a one-way layout. More specifically, assume

X_ij = m + t_j + e_ij,  i=1,...,n_j and j=1,...,k,

where the errors are idependent and identically distributed. Then you
can use the Jonckheere-Terpstra to test

H_0:t_1=t_2=...=t_k
against
H_A:t_1=t_2=...=t_k,

where at least one of the inequalities is strict.

To my knowledge there is no R code for this test but the test statistic
is not too hard to calculate (you have to calculate some Mann-Whitney
counts) and the p-value can be found in a table - or in case you have
many observations you can use a large-sample approximation. 

The original article appeared in 
Biometrika, Vol. 41, No. 1/2. (Jun., 1954), pp. 133-145

But it is probably easier to read page 120-123 in
Nonparametric statistical methods by Hollander and Wolfe (1973) Wiley
 Sons.

A NOT-distribution-free alternative to this test is described in 
Biometrika, Vol. 72, No. 2. (Aug., 1985), pp. 476-480.

Kim.
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 5. oktober 2003 14:51
To: [EMAIL PROTECTED]
Subject: [R] Jonckheere-Terpstra test

Hello,

can anybody here explain what a Jonckheere-Terpstra test is and whether
it is
implemented in R? I just know it's a non-parametric test, otherwise I've
no
clue about it ;-( . Are there alternatives to this test?

thanks for help,

Arne

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Jonckheere-Terpstra test

2003-10-06 Thread Ted Harding
On 06-Oct-03 Kim Mouridsen wrote:
 The Jonckheere-Terpstra test is a distribution-free test for ordered
 alternatives in a one-way layout. More specifically, assume
 
 X_ij = m + t_j + e_ij,i=1,...,n_j and j=1,...,k,
 
 where the errors are idependent and identically distributed. Then you
 can use the Jonckheere-Terpstra to test
 
 H_0:t_1=t_2=...=t_k
 against
 H_A:t_1=t_2=...=t_k,
 
 where at least one of the inequalities is strict.

To be more precise: the Jonkheere test applies where H_A is stochastically
increasing in j (P[X_j = x] = P[X_j+1 = x], for all x, with inequality
for at least one j). When k=2, the Jonkheere statistic is the same as the
Mann-Whitney U. For k  2, it is the sum for j1 = 1:(k-1) of the sum
for j2 = (j1+1):k of the Mann-Whitney Us for samples j1 and j2. To apply
it cleanly, there is an assumption of no ties (as if variables were
continuous).

 To my knowledge there is no R code for this test but the test statistic
 is not too hard to calculate (you have to calculate some Mann-Whitney
 counts) and the p-value can be found in a table - or in case you have
 many observations you can use a large-sample approximation. 

I once published an algorithm for the exact distribution in JRSS C
(Applied Statistics), 1984, pp. 1-6.

This was devised in the days of programmable calculators and 64K 4MHz
micros when RAM and computation time were major issues. However, the code
is easily implemented and may be as straightforward as any, even now.

Let W denote the Jonkheere statistic. To compute the distribution of W
over the range 0:M use the following algorithm (which applies as it
stands to the M-W U statistic with sample sizes m, n).
NOTE that indexing starts at 0.

U[M,m,n]:
[A]  f(0) = 1 ; f(1) = ... = f(M) = 0
[B]  If (n+1  M) go to [C]
 P = min(m+n,M)
 for( t = (n+1):P )
   for( u = M:t ) ## Note reverse order: t = M,M-1,...,t
 f(u) = f(u) - f(u-t)

[C]  Q = min(m,M)
 for( s = 1:Q )
   for( u = s:M )
 f(u) = f(u) + f(u-s)

For Jongkheere with sample sizes n-1, n_2, ... , n_k, let

 N_i = n_(i+1) + ... + n_k ,  i = 1, 2, ... , k-1

Run the above first from [A] with m = n_1, n = N_1 and then repeatedly
from [B] with m = n_2, n = N_2; ... ; m = n_(k-1), n = N_(k-1) = n_k.

At the end, f(0), f(1), ... , f(M) will contain the frequencies (counts)
of the numbers of ways in which a value W = 0, 1, ... , M can arise
(purely combinatorial). On H_0, all redistributions of sample values
are equally likely, so to get the probability distribution divide by
the number of all possible reallocations (the combinatorial number of
choices of (n_1, n_2, ... , n_k) out of N = sum(n_i)).

Or you can compute the complete frequency distribution and divide each
term by the sum of all.

The above 'algorithmicises' the algebra of the generating function for
the counts.

Have fun!
Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 167 1972
Date: 06-Oct-03   Time: 13:10:25
-- XFMail --

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Jonckheere-Terpstra test

2003-10-05 Thread A.J. Rossini
[EMAIL PROTECTED] writes:

 can anybody here explain what a Jonckheere-Terpstra test is and whether it is
 implemented in R? I just know it's a non-parametric test, otherwise I've no
 clue about it ;-( . Are there alternatives to this test?

Search google.

The third one (at least on my hit) references a description I used
when teaching back in the dark ages.  The others seem relevant, too.

best,
-tony

-- 
[EMAIL PROTECTED]http://www.analytics.washington.edu/ 
Biomedical and Health Informatics   University of Washington
Biostatistics, SCHARP/HVTN  Fred Hutchinson Cancer Research Center
UW (Tu/Th/F): 206-616-7630 FAX=206-543-3461 | Voicemail is unreliable
FHCRC  (M/W): 206-667-7025 FAX=206-667-4812 | use Email

CONFIDENTIALITY NOTICE: This e-mail message and any attachme...{{dropped}}

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help