[RESOLVED] Standard Deviation Issues
Alright so im making a program that reads a text file that lists a persons name then next line has the persons test score. I am trying to calculate the standard deviation for any given amount of people. I got the mean calculation to work, but I can't seem to see why my standard deviation calculation doesnt work. Please check it out for me!
Code:
Dim name As String, total, x, n as Double
Dim sr As IO.StreamReader = IO.File.OpenText("scores.txt")
Dim count As Double = 0
Do While sr.peek <> -1
name = sr.ReadLine
total += CDbl(sr.ReadLine)
count += 1
Loop
Do While sr.Peek <> -1
name = sr.ReadLine
x = CDbl(sr.ReadLine)
n += ((x - total) ^ 2)
Loop
ListBoxdata.items.add("Mean = " & Math.Round(total/count, 1))
ListBoxdata.items.add("Standard Deviation = " & Math.Sqrt(n / count))
end sub
Standard Deviation Formula = http://en.wikipedia.org/wiki/Standard_deviation
Re: Standard Deviation Issues
try this:
vb Code:
x = CDbl(sr.ReadLine)
n += ((x - total) ^ 2)
Re: Standard Deviation Issues
actually, you need to put this before the 2nd do loop:
vb Code:
sr.dispose
sr = IO.File.OpenText("scores.txt")
Re: Standard Deviation Issues
The first post you suggested is the same thing I have?
I added the second post and that at least got me a number! But its the wrong number, its 360...
Re: Standard Deviation Issues
Quote:
Originally Posted by
mxzx440
The first post you suggested is the same thing I have?
you edited your typo:D
how far out is it?
try using decimals instead of doubles
Re: Standard Deviation Issues
Yeah, I noticed I had typed a _ instead of a ) when I looked at my post after I had already replied...haha wasn't trying to undermine you. Anyway, it is suppose to equal 8.9 with my data. Before it does the square root and dividing by 5, it should equal 390 something. So it is doing just about everything wrong...
Re: Standard Deviation Issues
this might be the problem:
Code:
Do While sr.Peek <> -1
name = sr.ReadLine
x = CDbl(sr.ReadLine)
n += ((x - total) ^ 2)
Loop
Quote:
compute the difference of each data point from the mean, and square the result
Re: Standard Deviation Issues
OH MY GOODNESS! That was it! Thank you soooooo much! I am going to rate you for sure! I knew a fresh set of eyes would help, so glad it was an easy error. I need to stop working on this so late at night...