Section 3.2 Summarizing a PMF
In Chapter 1 we computed the mean of a sample by adding up the elements and dividing by the number of elements. Hereβs a simple example.
$ seq = [1, 2, 2, 3, 5]
n = len(seq)
mean = np.sum(seq) / n
mean
np.float64(2.6)
Now suppose we compute the PMF of the values in the sequence.
pmf = Pmf.from_seq(seq)
Given the
Pmf, we can still compute the mean, but the process is different β we have to multiply the probabilities and quantities and add up the products.
$ mean = np.sum(pmf.ps * pmf.qs)
mean
np.float64(2.6)
Notice that we donβt have to divide by
n, because we already did that when we normalized the Pmf. Pmf objects have a mean method that does the same thing.
$ pmf.mean()
np.float64(2.6)
Given a
Pmf, we can compute the variance by computing the deviation of each quantity from the mean.
deviations = pmf.qs - mean
Then we multiply the squared deviations by the probabilities and add up the products.
$ var = np.sum(pmf.ps * deviations**2)
var
np.float64(1.84)
The
var method does the same thing.
$ pmf.var()
np.float64(1.84)
From the variance, we can compute the standard deviation in the usual way.
$ np.sqrt(var)
np.float64(1.3564659966250536)
Or the
std method does the same thing.
$ pmf.std()
np.float64(1.3564659966250536)
$ pmf.mode()
np.int64(2)
Weβll see more methods as we go along, but thatβs enough to get started.
