Results 1 to 4 of 4

Thread: Standard Deviation

  1. #1

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372

    Standard Deviation

    What the hell is standard deviation anyway?

    Well I wrote a prog to calculate the mean and standard devation of a set of numbers. The mean part was easy enough but I'm having probs with the standard deviation. Here is the code I'm using:
    VB Code:
    1. Dim X As Long
    2. Dim SumX1 As Single
    3. Dim SumX2 As Single
    4. Dim NumValues As Integer
    5.  
    6. 'Seperate Numbers'
    7. Array1 = Split(txtNumbers.Text, ",")
    8.    
    9. Total = 0
    10. For X = 0 To UBound(Array1)
    11.     Total = Total + Array1(X)
    12. Next X
    13.  
    14. SumX1 = SumX1 + Total
    15. SumX2 = SumX2 + Total ^ 2
    16. NumValues = UBound(Array1) + 1
    17.  
    18. 'Calculate and Display Mean
    19. Mean = SumX1 / NumValues
    20. lblMean.Caption = Mean
    21.  
    22. 'Calculate and Display Standard Deviation
    23. Stdev = Sqr((NumValues * SumX2 - SumX1 ^ 2) / (NumValues * (NumValues - 1)))
    24.  
    25. lblDeviation.Caption = Stdev

    I'm not getting the right answer for the standard deviation. So maybe one of you brainy guys could tell me where I've gone wrong.
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    VB Code:
    1. Dim X As Long
    2. Dim SumX1 As Single
    3. Dim SumX2 As Single
    4. Dim NumValues As Integer
    5.  
    6. 'Seperate Numbers'
    7. Array1 = Split(txtNumbers.Text, ",")
    8.    
    9. Total = 0
    10. For X = 0 To UBound(Array1)
    11.     Total = Total + Array1(X)
    12. Next X
    13.  
    14. SumX1 = SumX1 + Total
    15. 'not needed SumX2 = SumX2 + Total ^ 2
    16. NumValues = UBound(Array1) + 1
    17.  
    18. 'Calculate and Display Mean
    19. Mean = SumX1 / NumValues
    20. lblMean.Caption = Mean
    21.  
    22. 'Calculate and Display Standard Deviation
    23. for X=1 to NumValues
    24.     SumX2=(Array1(X)-Mean)*(Array1(X)-Mean)
    25. next X
    26. Stdev=Sqr(SumX2/(NumValues-1)
    27. lblDeviation.Caption = Stdev
    'I got that from German Explantion
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking

    yeah, Standard Deviation must be worked out Term-by-term, finiding the deviation of each term from the mean, squaring it, ading these squares up and finding the square root.

    Just a change to the code by opus:
    VB Code:
    1. 'SumX2=(Array1(X)-Mean)*(Array1(X)-Mean)
    2. 'should be
    3. SumX2=SumX2 + (Array1(X)-Mean)^2

    I think this is needed, otherwise the sum at the end is just the (deviation of the last value from the mean) squared.
    sql_lall

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Think of standard deviation as how spread out a frequency distribution curve is. This curve is the famous 'bell-shaped' curve.

    If the curve has steep sides (narrow) the std dev is small.
    IF the sides are spread out, the std is large.
    std dev is called 'sigma', and 95% of the population lies within the area under the curve defined by:

    ( mean +/- 2 * sigma).

    Standard deviation is a way to see if one data set, for example= height measurements, is a part of the population.

    In plain English, you use it to find if your measurements match another group of measurements or not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width