Scipy standard deviation
python, scipy
Solution
The basic reason is that you're taking the standard deviation of two quite different things there. I think you're misunderstanding what `scipy.stats.binom` does. From the documentation:
The probability mass function for binom is:
`binom.pmf(k) = choose(n,k) * p**k * (1-p)**(n-k)`
for k in {0,1,...,n}.
binom takes n and p as shape parameters.
When you do `binom(189, 100/189)`, you are creating a distribution that could take on any value from 0 to 189. This distribution unsurprisingly has a much larger variance than the other sample data you're using, which is restricted to values of either zero or one.
It looks like what you want would be `scipy.stats.binom(1, 100/189).std()`. However, you still can't expect the exact same value as what you're getting with your sample data, because the `binom.std` is computing the standard deviation of the overall distribution, whereas the other version (`scipy.stats.tstd([1]*100 + [0]*89)`) is computing the standard deviation only of a sample. If you increase the size of your sample (e.g., do `scipy.stats.tstd([1]*1000 + [0]*890)`), the sample standard deviation will approach the value you're getting from `binom.std`.
You can also get the population (not sample) std by using `scipy.std` or `numpy.std` instead of `scipy.stats.tstd`. `scipy.stats.tstd` doesn't have a `ddof` option to let you choose the degrees of freedom, and always computes a sample `std`.
Problem
I'm trying to calculate standard deviation for some distribution and keep getting two different results from two paths. It doesn't make much sense to me - could someone explain why is this happening? ``` scipy.stats.binom(189, 100/189).std() 6.8622115305451707 scipy.stats.tstd([1]*100 + [0]*89) 0.50047821327986164 ``` Why aren't those two numbers equal?