Here I found a formula for the sample standard deviation:


Here is my simulation:

enter image description here

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 = {};
  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?

  • $\begingroup$ 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. $\endgroup$ – Roman May 27 '19 at 12:47
  • $\begingroup$ I added P from the cited site. $\endgroup$ – azzteke May 27 '19 at 12:57

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}]]

enter image description here

  • $\begingroup$ Thanks. My obvious mistake. $\endgroup$ – azzteke May 27 '19 at 13:04
  • $\begingroup$ @azzteke it's not obvious at all. $\endgroup$ – Roman May 27 '19 at 13:08
  • $\begingroup$ I was irritated by equation(1) in that article, where there was a factor of 1/N $\endgroup$ – azzteke May 27 '19 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.