Returns one row per row of the starting data and one logical column per
criterion, recording whether the row passed (TRUE), failed (FALSE), or
has no result (NA) for that criterion. Use it to audit who failed what,
or to plot overlapping exclusion reasons, which the step-by-step cascade
hides. To get the cohort itself, use cohort().
Arguments
- flow
A
cf_flowobject produced byapply_criteria().- mode
"cumulative"(default) or"independent"; see the section "Modes".- sets
"pass"(default) reports whether each row passed each criterion;"fail"negates every criterion column (NAstaysNA), soTRUEmarks the reasons a row fails.- na
What to do with
NAin the criterion columns, applied aftersets:"keep"(default) leaves them;"false"replaces them withFALSE;"drop"removes rows with anyNA.- names
Criterion column names:
"label"(default) uses step labels, made unique with a warning if repeated;"step"usescf_step_<n>. A name that clashes with an id or data column is made unique with a warning.- drop_randomise
Logical. Omit
randomise()steps (defaultTRUE).- keep_data
Logical. Include the original data columns between the id column(s) and the criterion columns (default
FALSE).- as
Return type:
"tibble"(default),"data.table"(requires the data.table package), or"matrix", a logical matrix of the criterion columns only, with the row identifier as row names (keep_datais ignored).
Value
For "tibble" and "data.table": the id column(s) given as id
to apply_criteria() (or .cf_row_id if none was given), then the data
columns if keep_data = TRUE, then one logical column per criterion in
step order. Rows are in the original data order. For "matrix": a
logical matrix.
Modes
| Value | mode = "cumulative" | mode = "independent" |
TRUE | Reached the step and passed it | The criterion holds for the row |
FALSE | Removed at this step | The criterion fails for the row |
NA | Not assessed: removed at an earlier step | The predicate gave NA, or a grouped step's by is NA |
Cumulative mirrors the cascade used by cohort(), excluded() and the
CONSORT diagram, and is built from the recorded steps without re-evaluating
anything. Each row has at most one FALSE. NA means the row never
reached that criterion, which is not the same as failing it; it only
becomes FALSE if you ask for that with na = "false". Missing predicate
values follow the cascade: an include() that evaluates to NA removes
the row (FALSE), an exclude() that evaluates to NA keeps it (TRUE).
Independent evaluates every criterion against the full starting data, ignoring earlier steps, so a row can fail several criteria. Bear in mind:
group_include(),group_exclude()andselect_within()depend on which rows are in each group. Evaluated on the full data, a group can pass or fail differently than it did in the cascade, where earlier steps had already removed some of its rows.In a
continue_criteria()flow, columns joined at a later stage areNAfor rows excluded before the join, so later-stage predicates are usuallyNAfor those rows.randomise()steps are allTRUE(in cumulative mode they areTRUEwhere reached andNAotherwise). They are dropped by default.
Set plots
Set and overlap plots (e.g. the eulerr, UpSetR or ComplexUpset packages)
take a membership matrix with no missing values. The usual question is how
exclusion reasons overlap, so ask for failures and decide what NA
means:
See also
cohort() for the cohort itself, excluded() for removed rows.
Other flow accessors:
cohort(),
excluded(),
stack_cohorts()
Examples
dat <- mock_parallel_rct(n_participants = 200, seed = 1)
crit <- cf_criteria() |>
include(~ age >= 18, label = "Adults only") |>
include(~ eligible_screen, label = "Passed screening") |>
exclude(~ withdrew, label = "Withdrew consent")
flow <- apply_criteria(dat, crit, id = "participant_id")
criteria_status(flow)
#> # A tibble: 200 × 4
#> participant_id `Adults only` `Passed screening` `Withdrew consent`
#> <chr> <lgl> <lgl> <lgl>
#> 1 P0001 TRUE FALSE NA
#> 2 P0002 TRUE TRUE TRUE
#> 3 P0003 TRUE TRUE TRUE
#> 4 P0004 TRUE TRUE TRUE
#> 5 P0005 TRUE TRUE TRUE
#> 6 P0006 TRUE TRUE TRUE
#> 7 P0007 TRUE TRUE TRUE
#> 8 P0008 TRUE TRUE TRUE
#> 9 P0009 TRUE FALSE NA
#> 10 P0010 TRUE TRUE TRUE
#> # ℹ 190 more rows
# How often each exclusion reason applies, counting overlaps
m <- criteria_status(flow, mode = "independent", sets = "fail",
na = "false", as = "matrix")
colSums(m)
#> Adults only Passed screening Withdrew consent
#> 6 17 7