Free Hosting : Drug Rehab : Free Web Hosting : Credit Card Offers

Calculating the Mean and Standard Deviation


[Summary] [Algorithm] [Example]

Summary

  • We want to calculate both the mean and standard deviation in one pass through the data without round-off errors.
  • This is the kind of algorithm used in pocket calculators.
  • It takes more paper but has several advantages.
    1. This method also allows you to notice peculiar observations as soon as they appear.
    2. We avoid round-off errors by carrying the maximum possible precision.

Algorithm

  1. Make a table with five (5) columns and one row for each observation.
  2. Label the first column n, the second column X, the third column d, the fourth column M, and the fifth column SS.
  3. Write "1" in the n column, the 1st observation in the X column and the M column, and 0 in the d and SS columns.
  4. For each observation after the first, write
    1. the observation sequence number in the n column. (This column will have the entries 1,2,... when finished.)
    2. the next observation in the X column
    3. (X - M)/n in the d column. (using the M from the previous row)
    4. M + d in the M column, using the M from the previous row again.
    5. SS + n(n-1)d in the SS column. (using the SS from the previous row)
  5. When you have finished, divide the SS from the last row by (n-1). This result is the variance of X from this sample.
  6. Take its square root. This number is the standard deviation of X from this sample.

Example

nXdMSS
17000
29182
38082
48082
57-0.27.82.8
690.284.0
SS / (n-1) = 4.0 / 5 = 0.8
and the square root of 0.8 is (approximately) 0.894 which is the sd.
DickBeldin@prdigital.com