|
-
Nov 17th, 2009, 10:37 PM
#1
Thread Starter
Junior Member
[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
Last edited by mxzx440; Nov 17th, 2009 at 11:31 PM.
-
Nov 17th, 2009, 10:51 PM
#2
Re: Standard Deviation Issues
try this:
vb Code:
x = CDbl(sr.ReadLine)
n += ((x - total) ^ 2)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 17th, 2009, 10:57 PM
#3
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")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 17th, 2009, 11:17 PM
#4
Thread Starter
Junior Member
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...
-
Nov 17th, 2009, 11:40 PM
#5
Re: Standard Deviation Issues
 Originally Posted by mxzx440
The first post you suggested is the same thing I have?
you edited your typo
how far out is it?
try using decimals instead of doubles
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 17th, 2009, 11:43 PM
#6
Thread Starter
Junior Member
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...
-
Nov 17th, 2009, 11:56 PM
#7
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
compute the difference of each data point from the mean, and square the result
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 18th, 2009, 01:17 AM
#8
Thread Starter
Junior Member
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|