Skip to main content

Section 14.3 Distribution of Sample Means

If we can compute the distribution of a sample sum, we can also compute the distribution of a sample mean. To do that, weโ€™ll use a third property of a normal distribution: if we multiply or divide by a constant, the result is a normal distribution. The following methods show how we compute the parameters of the distribution of a product or quotient.
Listing 14.3.1. Python Code
%%add_method_to Normal


def __mul__(self, factor):
    """Multiplies by a scalar."""
    return Normal(factor * self.mu, factor**2 * self.sigma2)
Listing 14.3.2. Python Code
%%add_method_to Normal


def __truediv__(self, factor):
    """Divides by a scalar."""
    return self * (1 / factor)
To compute the distribution of the product we multiply the mean by factor and the variance by the square of factor. We can use this property to compute the distribution of the sample means.
Listing 14.3.3. Python Code
dist_mean_male = dist_sums_male / n
To see if the result is correct, weโ€™ll also compute the means of the random samples.
Listing 14.3.4. Python Code
sample_means_male = np.array(sample_sums_male) / n
And compare the normal model to the empirical CDF of the sample means.
Listing 14.3.5. Python Code
dist_mean_male.plot_cdf(**model_options)
Cdf.from_seq(sample_means_male).plot(label="sample")

decorate(xlabel="Average weight (g)", ylabel="CDF")
Figure 14.3.6.
The model and the simulation results agree, which shows that we can compute the distribution of the sample means analyticallyโ€”which is very fast, compared to resampling.
Now that we know the sampling distribution of the mean, we can use it to compute the standard error, which is the standard deviation of the sampling distribution.
Listing 14.3.7. Python Code
$ standard_error = np.sqrt(dist_mean_male.sigma2)
standard_error
np.float64(40.591222045992765)
This result suggests a shortcut we can use to compute the standard error directly, without computing the sampling distribution. In the sequence of steps we followed, we multiplied the variance by n and then divided by n**2โ€”the net effect was to divide the variance by n, which means we divided the standard deviation by the square root of n.
So we can compute the standard error of the sample mean like this.
Listing 14.3.8. Python Code
$ standard_error = weights_male.std() / np.sqrt(n)
standard_error
np.float64(40.59122204599277)
Now letโ€™s consider one more result we can compute with normal distributions, the distribution of differences.