def group_privilege_var(df_cm, var, privilege_var, privilege_fn):
    """Group a confusion matrix df by privileged var, applying is_privileged_fn."""
    cm_priv = (
        df_cm.reset_index()
        .assign(
            var=var,
            privilege_var=privilege_var,
            is_privileged=privilege_fn,
        )
        .groupby(["var", "privilege_var", "is_privileged"])[["tn", "fp", "fn", "tp"]]
        .sum()
    )
    return cm_priv