Add an inclusion criterion to a criteria pipeline
Arguments
- criteria
A
cf_criteriaobject (orNULLto start a new one).- predicate
A one-sided formula or a function evaluated row-wise.
- label
A short human-readable description of this criterion. See the Labels section.
- category
An optional string grouping this step with others for display (e.g.
"Valid age").NULLleaves it uncategorised.- reason
An optional short description of the rows this step removes, shown in diagram exclusion boxes.
NULL(default) useslabelfor exclusion steps; for inclusion steps it should be set. See the Labels section.
Missing values
A predicate that evaluates to NA for a row is treated differently by the
two step types, and the difference changes denominators:
include()treatsNAas failing: the row is removed. Writeinclude(~ age >= 18)and rows with missingageare excluded here.exclude()treatsNAas not matching: the row is kept. Writeexclude(~ withdrew)and rows with missingwithdrewstay in.
To make the intent explicit, handle NA in the predicate itself, e.g.
include(~ !is.na(age) & age >= 18) or exclude(~ is.na(withdrew) | withdrew).
Grouped steps (group_include(), group_exclude(), select_within())
always remove rows whose by value is NA. To see the raw predicate
values, NA included, use criteria_status() with mode = "independent".
Labels
A step has up to two pieces of text, and diagrams put each next to the count it describes:
labelnames the step. Forinclude(),group_include()andselect_within()it describes the rows kept ("Aged 18 or over"), and an uncategorised step's main box inas_consort_diagram()shows it with the number remaining. Forexclude()andgroup_exclude()it describes the rows removed ("Withdrew consent"), so the diagram shows it in the exclusion box with the number removed, and the main box below reads "Remaining (n = ...)".reasondescribes the rows removed, for exclusion boxes. Exclusion steps default to their label. For inclusion steps the label would read backwards in an exclusion box ("Aged 18 or over (n=6)" for six people under 18), so give areason("Under 18"). Without one, an uncategorised inclusion step's exclusion box just says "Excluded", and one listed under a category falls back to its label with a warning.
Attrition tables list every step by label, beside a "Removed" column.
See also
Other criteria builders:
cf_criteria(),
cf_criterion(),
check_criteria(),
exclude(),
group_exclude(),
group_include(),
randomise(),
select_within()
Examples
cf_criteria() |>
include(~ age >= 18, label = "Adults", category = "Valid age",
reason = "Under 18")
#> Cohort criteria pipeline (1 step)
#> 1. [+][~] (include) {Valid age} Adults
#> age >= 18
#> removes: Under 18