What This Calculator Does
This tool computes the variance and standard deviation of a discrete random variable from its probability distribution. You supply each possible outcome (\(x_i\)) and the probability of that outcome (\(p_i\)), and the calculator returns the variance Var(X), the mean \(\mu\), the expected value of \(X^2\), and the standard deviation \(\sigma\). Variance measures how spread out the outcomes are around the mean — a small variance means outcomes cluster near the average, while a large variance means they are widely dispersed.
How to Use It
Enter the outcomes as a comma-separated list in the first box (for example 1, 2, 3). Enter the matching probabilities in the same order in the second box (for example 0.2, 0.5, 0.3). The probabilities should sum to 1; the calculator reports \(\sum p_i\) so you can verify this. Click calculate to see the variance and related statistics.
The Formula Explained
The variance uses the convenient computational form:
$$\operatorname{Var}(X) = \sum p_i x_i^{2} - \left(\sum p_i x_i\right)^{2}$$Here \(\sum p_i x_i\) is the mean \(\mu = E[X]\), and \(\sum p_i x_i^{2}\) is \(E[X^2]\). Subtracting the square of the mean from \(E[X^2]\) gives the variance. This is algebraically identical to the definition \(\operatorname{Var}(X) = \sum p_i (x_i - \mu)^2\) but is easier to compute in one pass. The standard deviation is simply \(\sigma = \sqrt{\operatorname{Var}(X)}\).
Worked Example
Suppose X takes values 1, 2, 3 with probabilities 0.2, 0.5, 0.3. The mean is $$\mu = 1(0.2) + 2(0.5) + 3(0.3) = 0.2 + 1.0 + 0.9 = 2.1.$$ $$E[X^2] = 1(0.2) + 4(0.5) + 9(0.3) = 0.2 + 2.0 + 2.7 = 4.9.$$ So $$\operatorname{Var}(X) = 4.9 - 2.1^{2} = 4.9 - 4.41 = 0.49,$$ and \(\sigma = \sqrt{0.49} = 0.7\).
More Worked Examples
Example 1: A fair six-sided die
Outcomes are \(x = 1, 2, 3, 4, 5, 6\), each with \(p_i = \frac{1}{6}\).
- Mean: \(E[X] = \sum p_i x_i = \frac{1}{6}(1+2+3+4+5+6) = \frac{21}{6} = 3.5\).
- Second moment: \(E[X^2] = \sum p_i x_i^2 = \frac{1}{6}(1+4+9+16+25+36) = \frac{91}{6} \approx 15.1667\).
- Variance: \(\sigma^2 = E[X^2] - (E[X])^2 = \frac{91}{6} - 3.5^2 = 15.1667 - 12.25 \approx 2.9167\) (exactly \(\frac{35}{12}\)).
- Standard deviation: \(\sigma = \sqrt{2.9167} \approx 1.7078\).
Example 2: A game payoff with losses and gains
A game pays \(x = -10, 0, 20\) (in dollars) with probabilities \(p = 0.5, 0.3, 0.2\). The probabilities sum to 1.
- Mean: \(E[X] = 0.5(-10) + 0.3(0) + 0.2(20) = -5 + 0 + 4 = -1\).
- Second moment: \(E[X^2] = 0.5(100) + 0.3(0) + 0.2(400) = 50 + 0 + 80 = 130\).
- Variance: \(\sigma^2 = 130 - (-1)^2 = 130 - 1 = \) 129.
- Standard deviation: \(\sigma = \sqrt{129} \approx 11.36\) dollars.
Note that the mean is squared in the last step, so a negative mean still gives a positive subtraction term.
Comparing Distributions with the Same Mean
All three distributions below have mean 2, but their spread differs. Variance captures that difference, which the mean alone cannot.
| Distribution | Mean E[X] | E[X²] | Variance | Std. deviation |
|---|---|---|---|---|
| x = 2 with p = 1 | 2 | 4 | 0 | 0 |
| x = 1, 2, 3 with p = 0.25, 0.5, 0.25 | 2 | 0.25 + 2 + 2.25 = 4.5 | 4.5 − 4 = 0.5 | ≈ 0.7071 |
| x = 0, 2, 4 with p = 0.25, 0.5, 0.25 | 2 | 0 + 2 + 4 = 6 | 6 − 4 = 2 | ≈ 1.4142 |
The third distribution uses outcomes twice as far from the mean as the second, so its variance is four times larger (2 vs 0.5) and its standard deviation is twice as large.
Interpreting Variance and Standard Deviation
- Variance 0: the outcome is constant (a degenerate distribution); all probability sits on one value, which equals the mean.
- Larger σ means wider spread: outcomes tend to fall farther from the mean E[X].
- Units: if X is measured in dollars, the variance is in dollars squared, while the standard deviation \(\sigma = \sqrt{\sigma^2}\) is in the same units as X (dollars), which makes it easier to interpret.
- Linear transformations: \(\mathrm{Var}(aX + b) = a^2\,\mathrm{Var}(X)\). Adding a constant b shifts the distribution without changing its spread; multiplying by a scales the standard deviation by \(|a|\).
- Independent sums: if X and Y are independent, \(\mathrm{Var}(X + Y) = \mathrm{Var}(X) + \mathrm{Var}(Y)\), and also \(\mathrm{Var}(X - Y) = \mathrm{Var}(X) + \mathrm{Var}(Y)\). Standard deviations do not add directly.
- Sensitivity to extremes: because deviations are squared, a rare but extreme outcome can raise the variance considerably, even when its probability is small.
Variance is never negative. If your calculation gives a negative value, check that the probabilities sum to 1 and that each pᵢ is between 0 and 1.
FAQ
Do the probabilities have to add to 1? Yes, for a valid distribution. The calculator shows \(\sum p_i\) so you can confirm. If it isn't 1, your results will be inaccurate.
What is the difference between variance and standard deviation? Variance is in squared units; standard deviation is its square root, expressed in the same units as X, which makes it easier to interpret.
Can variance be negative? No. Mathematically variance is always \(\geq 0\). A negative result indicates a data-entry error in the probabilities.