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.
%%add_method_to Normal
def __mul__(self, factor):
"""Multiplies by a scalar."""
return Normal(factor * self.mu, factor**2 * self.sigma2)
%%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.
dist_mean_male = dist_sums_male / n
To see if the result is correct, weโll also compute the means of the random samples.
sample_means_male = np.array(sample_sums_male) / n
And compare the normal model to the empirical CDF of the sample means.
dist_mean_male.plot_cdf(**model_options)
Cdf.from_seq(sample_means_male).plot(label="sample")
decorate(xlabel="Average weight (g)", ylabel="CDF")

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.
$ 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.
$ 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.
