Create a custom analysis layer
group_analyze.RdAllows a user-defined function to compute summary statistics. The function receives a data subset and the target variable name for each group combination, and returns a data.frame of results.
Usage
group_analyze(
target_var,
by = NULL,
where = NULL,
analyze_fn,
settings = layer_settings()
)Details
The analyze_fn is called once per group combination (defined by
cols and by data variables). It receives:
.data: A data.frame subset for the current group.target_var: Character string with the target variable name(s)
If format_strings are provided in settings, analyze_fn should
return a single-row data.frame of named numeric values. Each format string
entry becomes one output row, with its name used as the row label.
If no format_strings are provided, analyze_fn must return a
data.frame with row_label and formatted columns.
Note that analyze_fn is called once per cols x by
combination, so it only ever sees a single treatment column at a time — it
cannot compute a statistic across the treatment columns. For an
omnibus association test that spans the columns (e.g. Fisher's exact or CMH
on a count/shift layer), see assoc_test.
See also
assoc_test for cross-column association tests.