Expected value and variance for a discrete random variable
A discrete random variable \(X\) takes values from a finite or countable set, such as
\(x_1, x_2, \dots\). Its behavior is described by a probability mass function (PMF),
where each value has an associated probability \(P(X=x_i)=p(x_i)\).
The probabilities must satisfy two basic rules: \(p(x_i)\ge 0\) for all \(i\), and
\(\sum_i p(x_i)=1\). From a PMF table, two of the most important summaries are the
expected value (mean) and the variance (spread).
Expected value as a weighted average
The expected value \(\mathbb{E}[X]\) is the long-run average of \(X\) over many repeated experiments.
In discrete form, it is a weighted sum of the possible outcomes, with weights given by their probabilities:
\[
\mathbb{E}[X] = \sum_i x_i\,p(x_i).
\]
This looks like an average because probabilities act like “fractions of time” you expect to see each value.
For example, if \(X\) equals 1 with probability 0.3 and equals 2 with probability 0.7, then
\(\mathbb{E}[X]=1(0.3)+2(0.7)=1.7\). Notice the mean does not have to be one of the values \(X\) can take.
Second moment and variance
The variance measures how far outcomes tend to lie from the mean. One definition is
\(\mathrm{Var}(X)=\mathbb{E}\!\left[(X-\mathbb{E}[X])^2\right]\),
but for calculation it is often easier to use the identity
\[
\mathrm{Var}(X)=\mathbb{E}[X^2]-\big(\mathbb{E}[X]\big)^2.
\]
Here \(\mathbb{E}[X^2]\) is called the second moment:
\[
\mathbb{E}[X^2]=\sum_i x_i^2\,p(x_i).
\]
Once you have \(\mathrm{Var}(X)\), the standard deviation is
\(\sigma=\sqrt{\mathrm{Var}(X)}\), which has the same units as \(X\) and is often easier to interpret.
Checks and practical details
A good habit is to check \(\sum p(x)=1\). If your probabilities come from relative frequencies or rounded decimals,
the sum might be slightly off. In that case you can either treat it as a warning (keeping the values as entered)
or normalize the probabilities by dividing each \(p(x)\) by the total sum so they add to 1.
Another practical issue is repeated \(x\)-values: if a value appears multiple times in a table, you can merge them by adding the probabilities.
How to use this tool
Enter the PMF table as pairs \((x, p(x))\), one per line. The calculator computes \(\mathbb{E}[X]\),
\(\mathbb{E}[X^2]\), \(\mathrm{Var}(X)\), and \(\sigma\), and it shows clear steps based on weighted sums.
The interactive chart draws PMF bars and a vertical mean line.
Press Play to sweep through the list of outcomes and watch partial sums build intuition for how each outcome contributes to the mean and variance.
As you move into university topics, the same “moment” idea generalizes to higher moments like \(\mathbb{E}[X^3]\) and to transformations such as \(\mathbb{E}[g(X)]\).