home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / mann_whitney.pro < prev    next >
Encoding:
Text File  |  1997-07-08  |  3.1 KB  |  138 lines

  1. ; $Id: mann_whitney.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1991-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6.  
  7. function compute_rank, x , SortD
  8. list = where( sortD EQ x,count)
  9. return, list(0) + (count-1)/2.0
  10. END
  11.  
  12.  
  13. pro mann_whitney, Pop, U0, U1,n1,n2,Z,Prob, Missing=M
  14. ;+ 
  15. ; NAME:
  16. ;    MANN_WHITNEY
  17. ;
  18. ; PURPOSE:
  19. ;    To test the null hypothesis that two populations have the same
  20. ;    distribution -i.e. F(x) = G(x) against the alternative that their
  21. ;    distributions differ in location, i.e F(x) = G(x+a).  MANN_WHITNEY 
  22. ;    is a rank test that does not assume equal population sizes.
  23. ;
  24. ; CATEGORY:
  25. ;    Statistics.
  26. ;
  27. ; CALLING SEQUENCE:
  28. ;    MANN_WHITNEY, Pop [, U0, U1, N1, N2, Z, Prob, MISSING = M]
  29. ;
  30. ; INPUTS:
  31. ;    Pop:    Array dimensioned (2,Maxsize).  Pop(i,j) = jth observation
  32. ;        from ith population, i = 0, 1.
  33. ;  
  34. ; KEYWORDS: 
  35. ;      MISSING:    Value used as a place holder for missing data.  Pairwise
  36. ;        handling of missing data.
  37. ;
  38. ; OPTIONAL OUTPUT PARAMETERS:
  39. ;    U0:    MANN_WHITNEY statistic for Population 0.
  40. ;    U1:    MANN_WHITNEY statistic for Population 1.     
  41. ;    N1:    Size of sample from Pop(0,*)
  42. ;    N2:    Size of sample from Pop(1,*)
  43. ;    Z:    Test statistic,almost normal, to be used
  44. ;        when sample sizes exceed 10. Otherwise, Z=0.
  45. ;    Prob:    Probablity of Z or something more extreme.
  46. ;        Undefined for small sample sizes.
  47. ;
  48. ; RESTRICTIONS: 
  49. ;    All populations have the same sample size.
  50. ;
  51. ; COMMON BLOCKS:
  52. ;    None.
  53. ;
  54. ;PROCEDURE:  
  55. ;    The Mann_Whitney statistics Ua may be computed by ordering all 
  56. ;    observations according to their magnitude and counting the number
  57. ;    of observations in the first sample that precede each observation
  58. ;    in the second. Ub may be computed likewise. Very large or very small
  59. ;    values of UA or UB indicate seperation in the data and suggest 
  60. ;    rejection of the null hypothesis. 
  61. ;-             
  62.  
  63.  
  64.  
  65.  
  66.  
  67. On_Error,2
  68. SD= size(Pop)
  69.  
  70. unit =-1
  71. if ( SD(0) NE 2) THEN BEGIN
  72.    printf,unit, 'mann_whitney- Data array has wrong dimension'
  73.    goto, DONE
  74. ENDIF
  75.  
  76. C=SD(1)
  77. R= SD(2)
  78.  
  79. if (C LT 2) THEN BEGIN
  80. printf,unit,'mann_whitney- need more than 1 population'
  81. goto,done
  82. ENDIF
  83.  
  84. if (C GT 2) THEN print,             $
  85.        'mann_whitney- we only compare first two populations'
  86.  
  87. Pop1 =Pop(0,*)
  88. Pop2 = Pop(1,*)
  89.  
  90. if N_Elements(M) NE 0 THEN BEGIN
  91.    here1 = where(Pop1 NE M, count)
  92.  
  93.    if count ne 0 THEN $
  94.       Pop1 = Pop1 (here1) $
  95.    else BEGIN
  96.      print, " Too many missing values"
  97.      return
  98.    ENDELSE
  99.  
  100.    here2 = where(Pop2 NE M, count)
  101.    if count ne 0 THEN $
  102.     Pop2 = Pop2( where (Pop2 NE M)) $
  103.    ELSE BEGIN
  104.     print, "Too many missing values"
  105.     return
  106.    ENDELSE
  107. ENDIF
  108.  
  109. n1 = N_Elements(Pop1)
  110. n2 = N_Elements(Pop2)
  111.  
  112. Merge = [Pop1,Pop2]
  113. SortT = Merge( sort(Merge))
  114.  
  115. U0 = 0
  116. for i = 0l,n1-1 DO U0 = U0 + compute_rank(Pop1(i), SortT) + 1
  117.  
  118. U1 = 0
  119. for i = 0l,n2-1 DO U1 = U1 + compute_rank(Pop2(i), SortT) + 1
  120.  
  121. U0 = n1 * n2 + n1 * (n1 + 1)/2. - U0
  122. U1 = n1 * n2 + n2 * (n2 +1)/2. - U1
  123.  
  124. if (n1 LE 10 or n2 LE 10) THEN  BEGIN
  125.  print,"mann_whitney- find probability of Z from table"
  126.  Prob = -1 
  127.  Z=0
  128. ENDIF else  BEGIN
  129.       E = n1*n2/2.
  130.       V = n1*n2*(n1 + n2 +1)/12.
  131.       Z = (U0-E)/sqrt(V)
  132.       Prob = 1 - gaussint(abs(z))
  133. ENDElSE
  134.  
  135. done:
  136. return
  137. end
  138.