# Standard Deviation

• Dec 15th 2005, 01:31 AM
kaizen
Standard Deviation
HI All,

I am trying to calculate the standard deviation of a given set of numbers.

E.g. 1,2,3,4,5

If i use excel and the STDEV function i get 1.58113883
which is all good. But if i go to http://invsee.asu.edu/srinivas/stdev.html and enter the same numbers I get 1.4142135623730951

Now the the problem i have is in a vb.net program I have written a function that returns the latter of the two numbers. Which i believe is wrong.

1. Which number is correct?

2. If anyone knows vb.net is the below code correct? This returns the second value of the two.

Public Function standard deviation(ByVal Inputdata() As Double) As Double

Dim DataAverage As Double = 0
Dim TotalVariance As Double = 0

DataAverage = SMA(Inputdata)'get our moving average value

For i = 0 To Inputdata.Length - 1
TotalVariance = (TotalVariance + Math.Pow((Inputdata(i) - DataAverage), 2))
Next

StandardDeviation = Math.Sqrt(TotalVariance / Inputdata.Length))

End Function

Any ideas? Or pointers.

Thanks
• Dec 15th 2005, 11:29 AM
CaptainBlack
The problem is that there are two entities out there calling themselves
"standard deviation"

$s_N=\sqrt{\frac{1}{N} \sum_{i=1}^N(x_i-\bar x)^2}$

which is the square root of the sample variance if $\{x_1,\ ..\ x_N \}$ is
a sample of size $N$ from some population. Or the square root of
the variance of a random variable which takes the values
$x_1,\ ..\ x_N$ with equal probability.

$s_{N-1}=\sqrt{\frac{1}{N-1} \sum_{i=1}^N(x_i-\bar x)^2}$

which is the square root of the bias corrected estimate of the
population variance that $\{x_1,\ ..\ x_N \}$ is a sample of size $N$ from.

Now which you use is up to you and could depend on what you wish to
do with it. But apparently $s_{N-1}$ is now commonly used in software
packages as the definition of standard deviation - with poor justification.

However for large samples these are very close and so the difference does
not matter, but if I were you I would stick to $s_N$.

RonL
• Dec 16th 2005, 09:14 AM
ThePerfectHacker
I just have a curious question. I never studied Probabilty nor Statistics in full detail but I happen to know what Strandard Deviation is. The question I have is why not use the Mean-Absolute Deviation instead? Is it because Standard Deviation is useful in Probability and Statistics? And if yes, where?
• Dec 16th 2005, 09:34 AM
CaptainBlack
Quote:

Originally Posted by ThePerfectHacker
I just have a curious question. I never studied Probabilty nor Statistics in full detail but I happen to know what Strandard Deviation is. The question I have is why not use the Mean-Absolute Deviation instead? Is it because Standard Deviation is useful in Probability and Statistics? And if yes, where?

A number of reasons, mainly related to analytic tractability.

One could possibly be because of the asymptotic relationship between
maximum likelihood estimators, and minimum variance estimators.

The ubiquity of the Normal Distribution, and variance being one of
its natural parameters.

Distributions are charaterised by their moments, and variance is
the 2-nd central moment.

Also the Mean Deviation is used - but not so frequently.

RonL
• Dec 18th 2005, 04:33 PM
kaizen
Thanks guys. Gives me a better idea of what is going on.

FYI I am using the calculation for looking at price action on a currency chart and deterring when it has moved too far from its average. Then taking trades with the anticipation of it reverting back to its mean/average.