Section D.4 Difference in Coefficient of Variation
The coefficient of variation is the ratio of the standard deviation to the mean, so it quantifies variability in relative terms. Hereโs a function that takes a sample and computes the difference in coefficients of variation for men and women.
def diff_cvs(sample):
"""Difference in CV (M minus female)
sample: DataFrame with `_SEX` and `HTM4` columns
returns: float
"""
grouped_heights = sample.groupby("_SEX")["HTM4"]
means = grouped_heights.mean()
stds = grouped_heights.std()
return -diff(stds / means)
And hereโs a sample from the sampling distribution of the differences.
t3 = sampling_dist(brfss, diff_cvs)
np.mean(t3)
Hereโs the sampling distribution and a 95% CI.
plot_sampling_distribution(t3, format_str="0.4f")
plt.title("Difference in coefficient of variation", fontsize=14)
The CI does not contain zero, so the difference is statistically significant. And the p-value is small.
p_value(t3)
But in practical terms, the difference is very small. The coefficients of variation are about 0.048.
grouped_heights = sample.groupby("_SEX")["HTM4"]
means = grouped_heights.mean()
stds = grouped_heights.std()
CVs = stds / means
CVs
If we express the difference in CVs as a percentage of the CVs, it is only about 1.4%.
np.mean(t3) / CVs * 100
By this measure of variability, menโs heights are slightly more variable than womenโs, but the difference is so small, it is unlikely to have any practical consequences.
Also, both standard deviation and coefficient of variation are affected by outliers, and we have seen that there are extreme values in this dataset that are probably not correct. Itโs possible that the apparent difference in variability, by these test statistics, is the result of data errors.
So letโs try again with a more robust statistic.
