Skip to main content

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.
Listing D.4.1. Python Code
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.
Listing D.4.2. Python Code
t3 = sampling_dist(brfss, diff_cvs)
np.mean(t3)
Hereโ€™s the sampling distribution and a 95% CI.
Listing D.4.3. Python Code
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.
Listing D.4.4. Python Code
p_value(t3)
But in practical terms, the difference is very small. The coefficients of variation are about 0.048.
Listing D.4.5. Python Code
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%.
Listing D.4.6. Python Code
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.