home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / pascal / 7759 < prev    next >
Encoding:
Text File  |  1992-12-30  |  1.7 KB  |  50 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!news.ccs.queensu.ca!slip206.telnet1.QueensU.CA!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Correlation Coefficient
  5. Message-ID: <dmurdoch.270.725775983@mast.queensu.ca>
  6. Lines: 38
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <92365.223423BOYDJ@QUCDN.QueensU.CA>
  10. Date: Thu, 31 Dec 1992 04:26:24 GMT
  11.  
  12. In article <92365.223423BOYDJ@QUCDN.QueensU.CA> Jeff Boyd <BOYDJ@QUCDN.QueensU.CA> writes:
  13. >Let
  14. >    n be the number of data pairs
  15. >    Sx  = sum of {x}
  16. >    Sy  = sum of {y}
  17. >    Sxx = sum of {x^2}
  18. >    Syy = sum of {y^2}
  19. >    Sxy = sum of {xy}
  20. >
  21. >Then
  22. >                           n(Sxy) - (Sx)(Sy)
  23. >      r  =  ---------------------------------------------
  24. >            sqrt[n(Sxx)-(Sx)(Sx)] * sqrt[n(Syy)-(Sy)(Sy)]
  25. >
  26. >This is the formula of choice for simple computations.
  27.  
  28. That's a fast way to calculate the correlation coefficient, but it's 
  29. probably not the best, because it can be very inaccurate.  It's badly 
  30. subject to rounding error in the three subtractions, because you're 
  31. possibly subtracting huge numbers from other nearly identical huge numbers.
  32.  
  33. A more stable and accurate way to calculate it is using two passes
  34. through the data.  On the first pass, calculate Xbar = Sx/n and Ybar = Sy/n.
  35. Then calculate the "corrected" sums of squares
  36.  
  37.   CSxx = sum of {(x-Xbar)^2}
  38.   CSyy = sum of {(y-Ybar)^2}
  39.   CSxy = sum of {(x-Xbar)(y-Ybar)}
  40.  
  41. and finally
  42.  
  43.   r = CSxy / sqrt(CSxx * CSyy)
  44.  
  45. If two passes are impossible, there are ways to calculate the corrected
  46. sums of squares in a single pass.  I think they share the stability of
  47. this calculation, but I can't remember the formulas right now.
  48.  
  49. Duncan Murdoch
  50.