Results 1 to 5 of 5

Thread: [RESOLVED] Mean And Standard Deviation

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    41

    Resolved [RESOLVED] Mean And Standard Deviation

    I seem to figure out why my code is not for finding mean and st dev because the code i wrote for finding the sum is working and mean = sum/N so im confused i think i might have the wrong formula/code for standard deviation tho..i just found it online.....

    Code:
     
    Private Sub btnDisplayMean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayMean.Click
    
            Dim Mean As Integer
            Dim Sum As Integer
            For J = 0 To MyArray.Count - 1
                Sum = Sum + MyArray(J)
                Mean = CInt(Sum / (MyArray.Count - 1))
            Next
            txtDisplayNumbers.Text = CStr(Mean)
        End Sub
    
    
        Private Sub btnDisplaySD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplaySD.Click
            Dim Mean As Decimal
            Dim Temp As Double
            Dim Temp2 As Double
            Dim StDev As Double
    
            For J = 0 To MyArray.Count - 1
    
                Temp2 = MyArray(J) - Mean
                Temp = Temp + Temp2 * Temp2
                StDev = Math.Sqrt(Temp / MyArray.Count - 1)
            Next
            txtDisplayNumbers.Text = CStr(StDev)
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Mean And Standard Deviation

    First up, why would you be calculating the mean inside a loop? The mean is just one value, right? So why would you calculate it more than once?

    Also, you say one thing:
    mean = sum/N
    yet you do something else:
    Code:
    Mean = CInt(Sum / (MyArray.Count - 1))
    You're making the same two errors with your std dev as well.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    41

    Re: Mean And Standard Deviation

    Quote Originally Posted by jmcilhinney View Post
    First up, why would you be calculating the mean inside a loop? The mean is just one value, right? So why would you calculate it more than once?
    Oh wow, im an idiot... I'm calculating it in a loop because of my professor(He's CRAZY) wants it that way...
    Ok thank you for your help!

  4. #4
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Mean And Standard Deviation

    Quote Originally Posted by rosleenXOXO View Post
    I'm calculating it in a loop because of my professor(He's CRAZY) wants it that way...
    It's possible that he would want the sum calculated in a loop. Then after the loop, calculate the mean from that sum.

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    41

    Re: Mean And Standard Deviation

    Quote Originally Posted by Evil_Giraffe View Post
    It's possible that he would want the sum calculated in a loop. Then after the loop, calculate the mean from that sum.
    I changed it to the way you said Thanks a bunch!

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