Overwrite a cohort's placeholders with the gold standard
Source:R/gold-standard.R
sdt_apply_gold_standard.RdJoins the gold-standard codebook onto a cohort, or onto any frame carrying a
card id, and replaces the named columns with the deck's own values. The
replaced columns are kept as <col>_original, so the provenance is not lost
and the inference that was there before can still be scored against the
truth that replaced it.
Usage
sdt_apply_gold_standard(
cohort,
gold,
on = "card",
replace = c("triage", "age", "sex"),
keep_original = TRUE
)Arguments
- cohort
A
cohortfromsdt_cohort(), or any data frame with a card id column.- gold
An
sdt_gold_standardfromsdt_read_gold_standard().- on
Name of the card id column in
cohort. Values may be padded ("07"), unpadded ("7") or numeric; all three join.- replace
Which columns to overwrite: any of
"triage","age"and"sex". Passcharacter()to join nothing and only stamptriage_source.- keep_original
Keep each replaced column as
<col>_original.
Value
cohort with the named columns replaced, the originals kept when
asked for, and a triage_source column reading "gold". A cohort comes
back a validated cohort; anything else comes back a
tibble::tibble(). The gold_applied attribute records what was done.
Details
In the TDSC corpus the three replaceable columns start out as a circular
surrogate (triage, the inter-team consensus call), a constant
(age) and an inference from the log's gendered wording (sex). After this
function they are the card's own values, and triage_source reads "gold"
so a downstream result can say which label it routed on. The engine routes
on triage, so which label sits there decides which question a simulation
answers.
Provenance
triage_source names where the label sitting in triage came from, so it
reads "gold" only when triage was among the columns replaced. Ask for a
subset that leaves triage alone and any existing source label is left
alone with it: a surrogate must never end up wearing the truth's label.
Examples
if (FALSE) { # \dontrun{
gold <- sdt_read_gold_standard("Patienten Codebook.xlsx")
truth <- sdt_apply_gold_standard(pooled, gold)
mean(truth$triage == truth$triage_original)
} # }