Skip to contents

The check that would have caught a swapped race label on the day: after a recode, the number of rows per label must equal the counts the source published for those labels. If they do not, the function also tries every permutation of the labels and says whether the observed counts match the published ones under some relabelling, which is the signature of labels attached to the wrong groups.

Usage

morie_marginals_verify(x, published, tolerance = 0, strict = TRUE)

Arguments

x

A character or factor vector after recoding.

published

Named numeric vector: label = published count.

tolerance

Absolute count tolerance per label (default 0).

strict

When TRUE (the default) a mismatch is an error, so a pipeline stops on the day. When FALSE the result is returned with ok = FALSE, the permutation that would explain the counts and the message the error would have carried.

Value

Invisibly, a list with counts (observed), published, ok, and permutation (the relabelling under which the observed counts match the published ones, or NULL). Errors when the counts disagree.

Examples

x <- c("White", "White", "Black", "Indigenous", "White", "Black")
morie_marginals_verify(x, c(White = 3, Black = 2, Indigenous = 1))