|
-
Feb 20th, 2003, 08:38 AM
#1
Thread Starter
Hyperactive Member
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:
Dim X As Long
Dim SumX1 As Single
Dim SumX2 As Single
Dim NumValues As Integer
'Seperate Numbers'
Array1 = Split(txtNumbers.Text, ",")
Total = 0
For X = 0 To UBound(Array1)
Total = Total + Array1(X)
Next X
SumX1 = SumX1 + Total
SumX2 = SumX2 + Total ^ 2
NumValues = UBound(Array1) + 1
'Calculate and Display Mean
Mean = SumX1 / NumValues
lblMean.Caption = Mean
'Calculate and Display Standard Deviation
Stdev = Sqr((NumValues * SumX2 - SumX1 ^ 2) / (NumValues * (NumValues - 1)))
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.
-
Feb 21st, 2003, 02:17 AM
#2
VB Code:
Dim X As Long
Dim SumX1 As Single
Dim SumX2 As Single
Dim NumValues As Integer
'Seperate Numbers'
Array1 = Split(txtNumbers.Text, ",")
Total = 0
For X = 0 To UBound(Array1)
Total = Total + Array1(X)
Next X
SumX1 = SumX1 + Total
'not needed SumX2 = SumX2 + Total ^ 2
NumValues = UBound(Array1) + 1
'Calculate and Display Mean
Mean = SumX1 / NumValues
lblMean.Caption = Mean
'Calculate and Display Standard Deviation
for X=1 to NumValues
SumX2=(Array1(X)-Mean)*(Array1(X)-Mean)
next X
Stdev=Sqr(SumX2/(NumValues-1)
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!
-
Feb 25th, 2003, 04:07 AM
#3
Fanatic Member
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:
'SumX2=(Array1(X)-Mean)*(Array1(X)-Mean)
'should be
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 
-
Feb 25th, 2003, 12:32 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|