s-news
[Top] [All Lists]

[no subject]

To: s-news@lists.biostat.wustl.edu
From: Sumithra Mandrekar <sumjay21@yahoo.com>
Date: Wed, 12 Dec 2001 17:34:39 -0800 (PST)
Hi,

I am encountering a strange problem while using the
following S-Plus routine, which computes the
difference between the mean and median of each triple
and assigns a 1, 0, or ?1 depending on the sign of the
difference. Below is my code:

dat <- sort(c(12.9,13.7,14.5,13.3,12.8,13.8,13.4))

This is the sorted data: 12.8 12.9 13.3 13.4 13.7 13.8
14.5

n <- length(dat)
z <- array(0, c(n-2, n-1, n))

for(i in 1:(n-2))
{
  i+1 -> b
  if(b < n)
 {  
   for(j in b:(n-1))
    {
      j+1 -> a
      if (a==n+1) {break}

         for(k in a:n)
          {     
           x <- (dat[i]+dat[j]+dat[k])/3 - dat[j]     

            z[i,j,k] <- sign(x)
         
           }
      }

   }
}

For some reason, when it compares 12.9, 13.3, and 13.7
which is the (2, 3, 5) triple comparison, the mean is
13.3 and median is 13.3 and so x should be 0, instead
the value of x is calculated as: 1.776357e-015.

Can someone please tell me why this is happening? And
is there a simpler approach to computing this for all
the triples without using the ?For? loops?

Thanks
Sumithra




__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

<Prev in Thread] Current Thread [Next in Thread>
  • [no subject], Sumithra Mandrekar <=
    • Re:, Mike Prager