Section D.5 Difference in Robust CV
As an alternative to the coefficient of variation, we can use a more robust measure of variability. One option is the ratio of the median absolute deviation (MAD) to the median. Hereโs a function that computes it.
def robust_cv(series):
"""Median absolute deviation.
series: Series of numbers
returns: float
"""
m = series.median()
deviations = series - m
return deviations.abs().median() / m
The following function computes the difference in robust CVs. The first line jitters the dataโotherwise we would get the same results from every resampling.
def diff_robust_cv(sample):
"""Difference in robust CV (M minus female)
sample: DataFrame with `_SEX` and `HTM4` columns
returns: float
"""
sample["HTM4"] += np.random.normal(0, 1, size=len(sample))
grouped_heights = sample.groupby("_SEX")["HTM4"]
rcvs = grouped_heights.apply(robust_cv)
return -diff(rcvs)
The robust CV of the sample is negative, which suggests that womenโs heights are more variable.
diff_robust_cv(sample)
Hereโs the sampling distribution.
t4 = sampling_dist(brfss, diff_robust_cv)
np.mean(t4)
plot_sampling_distribution(t4, format_str="0.4f")
plt.title("Difference in robust CV", fontsize=14)
And the p-value.
p_value(t4)
According to the robust CV, women are more variable, but again the difference is so small it has no practical consequences.
