# Sampling Standard Deviation

Here I found a formula for the sample standard deviation:

http://mathworld.wolfram.com/StandardDeviationDistribution.html

Here is my simulation: P[n_, σ_, s_] :=
(2 (n/(2 σ^2))^((n - 1)/2))/Gamma[(n - 1)/2] Exp[-n s^2/(2 σ^2)] s^(n - 2)

μ = 45;
σ = 12;
n = 15;
list = {};
Do[
data = RandomVariate[NormalDistribution[μ, σ], n];
list = Append[list, Sqrt[Variance[data]]], 50000]

Show[Histogram[list, 100, "PDF"], Plot[P[n, σ, s], {s, 0, 35}]]


Can anybody explain the shift between the histogram and the P-curve?

• Your P is not defined. Please make your code self-contained. As a first guess I would say that your P is not defined correctly, hence the deviation from the empirical distribution of standard deviations. – Roman May 27 '19 at 12:47
• I added P from the cited site. – azzteke May 27 '19 at 12:57

## 1 Answer

Your P is the distribution of the population standard deviation, whereas your random standard deviations are sample standard deviations. They differ by a factor of $$\sqrt{\frac{N-1}{N}}$$. Correct for this by multiplying the sample standard deviations by this factor, and it's a match:

list = Table[Sqrt[(n-1)/n]*StandardDeviation[RandomVariate[NormalDistribution[μ, σ], n]], {50000}];
P[s_] = 2(n/(2σ^2))^((n-1)/2)/Gamma[(n-1)/2]*E^(-((n*s^2)/(2σ^2)))*s^(n-2);
Show[Histogram[list, 100, "PDF"], Plot[P[s], {s, 0, 35}]] • Thanks. My obvious mistake. – azzteke May 27 '19 at 13:04
• @azzteke it's not obvious at all. – Roman May 27 '19 at 13:08
• I was irritated by equation(1) in that article, where there was a factor of 1/N – azzteke May 27 '19 at 13:20