Results 1 to 4 of 4

Thread: standard deviation program

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    cornwall, England
    Posts
    110

    standard deviation program

    please can anyone help me finish this program....going mad!!
    im trying to write a program that will compute the MEAN and STANDARD DEVIATION of a sequence of numbers.
    sorry :-( still learning vb6 ( and struggling) thanks Tink

    private Sub cboData_KeyPress(KeyAscii As integer)
    DimValue As Integer
    Value = Val(cboData.Text)
    If KeyAscii = 13 Then
    If Value >=0 Then
    cboData.AddItem Value
    cboData.Text = ""
    Else
    msgBox "sorry no negative numbers"
    End If
    End If
    End Sub



    private sub cmdMean_click()
    Dim Index, sum As integer
    IF cboData.ListCount>0 Then
    Sum = 0
    For Index = 0 To cboDataCount.ListCount - 1
    Sum = Sum + Val(cboData.List(Index))
    Next Index
    lblResult = Sum / (cboData.ListCount)
    Else
    MsgBox "No Data"
    End If
    End Sub


    Private Sub cmdStdDev_click

    ????????????????????????????????????????

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Standard deviation is simple:

    Number of elements is n:

    sqrt[SIGMA{x^2/n} - m^2]

    x is each element in turn; m is the mean.

    So your code would look like

    ' function to get s.d. (have mean stored in the Mean variable)
    For I = 1 to cboData.ListCount
    Sum = Sum + ((cboData.List(I) ^ 2) / cboData.ListCount)
    Next I
    Sum = Sum - (Mean^2)
    SD = Sqrt(Sum)
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Tried to email but your username wasn't found... anyway.

    My bad. Replace it with this line:

    sum=sum+((Val(cboData.List(I))^2)/cboData.ListCount)

    That should help.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  4. #4
    DerFarm
    Guest
    Hey Tink, I got some table lookups and Fishers_exact for getting p-values and other stuff.

    You want it?

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