Variance equation for a probability distribution:
$$ \sigma^2 = \sum_{i=1}^{N}(x_i-\mu)^2P(X=x_i) $$

Standard variance equation: $$ \sigma^2 = \frac{1}{N}\sum_{i=1}^{N}(x_i-\mu)^2 $$

I understand that since the expected value of a probability distribution is the same as the mean, the expected value of the square deviations from the mean (Equation 1) should be the same as the mean of the square deviations from the mean (Equation 2). However, they don't give the same answer when tried with the following test scenario.

Birds spotted Probability
1 0.1
2 0.1
3 0.3
4 0.3
5 0.1
6 0.1

The table gives the probability of spotting the quantity of birds (from 1 to 6 birds) at any given time.

The mean/expected value is the same and is equal to 3.5. But I get 2 different values for the variance - 1.849 (using equation 1) and 2.916 (using equation 2).

Question: Under what circumstances would the 2 equations give the same result? I'm not sure I fully understand equation 1.

I've written the following python script to compare the results from the 2 equations:

import numpy as np
a = [1,2,3,4,5,6]
prob = [0.1, 0.1, 0.3, 0.3, 0.1, 0.1]

# Variance
variancePD = 0
m = np.mean(a)
for i in range(0,6):
  variancePD += (((a[i] - m)**2) * prob[i])

varianceNormal = 0
for i in range(0,6):
  varianceNormal += ((a[i] - m)**2)
varianceNormal /= len(a)

# Mean
meanPD = 0
for i in range(0,6):
  meanPD += (a[i] * prob[i])

print(f'variancePD: {variancePD}, varianceNormal: {varianceNormal}\
      \nmeanPD: {meanPD}, mean: {m}')
  • $\begingroup$ Hi! Check my answer below and let me know if it answers your question. $\endgroup$
    – utobi
    Nov 13, 2022 at 5:09

1 Answer 1


You are actually applying the same formula for the variance (of a discrete random variable) to two different random variables $X$.

Indeed, in the first case, $X$ takes on values $x_{1},\ldots,x_{N}$ with probability $P(X=x_i)$ for $i=1,\ldots,N$. Whereas in the second case, $X$ takes on the same values but $P(X=x_i)=1/N$.

Thus, following your numerical example, in the first case, the variance is

$$\sigma^2 = 0.1(1-3.5)^2+0.1(2-3.5)^2 + \cdots+0.1(6-3.5)^2 = 1.85$$

In the second case, it would be

$$\sigma^2 = (1/6)(1-3.5)^2+(1/6)(2-3.5)^2 + \cdots+(1/6)(6-3.5)^2 = 2.917$$

Agreement between the "two formulas" is obtained only if the two probability distributions are the same.

  • $\begingroup$ Amazing, thanks for the explanation. Just to confirm I understand, is it a coincidence that the 2 distributions have the same mean of 3.5? If I assigned the probability of spotting 1 bird as 0.3 and the probability of spotting 4 birds as 0.1, I can now see that in the 2nd distribution that you've pointed out, the probability still remains 1/6 for each spotting and hence the mean doesn't change. But the 1st distribution will now have a different mean of 2.9. $\endgroup$
    – JJT
    Nov 13, 2022 at 14:09
  • 1
    $\begingroup$ You are welcome! For the expected value the formula is $E(X) = \sum_{i=1}^N P(X=x_i) x_i$; with uniform probability distribution it becomes $E(X) = \sum_{i=1}^N x_i/N$. $\endgroup$
    – utobi
    Nov 13, 2022 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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