News for hackers. Stuff that matters.
Re:Introduction to Statistics using NumPy by bckygldstn on Saturday September 09, 2017 @02:19PM (#15208387)
The formula you give for variance is the sample variance, with N - 1 as the divisor. It gives an unbiased estimate of the variance of a population, assuming X is a sample of that much larger population.

However, by default numpy gives you population variance, with N as the divisor. This assumes X is the entire population, which is different from R and Matlab.

As a result, the answer in your code is different from the formula just above it.

  np.var(X)
gives 207, while

  np.sum((np.array(X) - np.mean(X))**2) / (len(X) - 1)
gives 236. If you want the N-1 corrected sample variance from numpy you'd use

  np.var(X, ddof=1)
Re:Introduction to Statistics using NumPy by aisofteng on Saturday September 09, 2017 @07:45PM (#15209699)