From d76a95c01820b3f25ceb36ea8f996bf5ebb2b1e4 Mon Sep 17 00:00:00 2001 From: Konrad Pagacz Date: Tue, 17 Sep 2024 10:00:47 +0200 Subject: [PATCH] feat: added "fraction" statistic to the "analyze_var_count" method group (#1309) Signed-off-by: Konrad Pagacz --- NEWS.md | 1 + R/analyze_variables.R | 4 + R/utils_default_stats_formats_labels.R | 2 +- tests/testthat/_snaps/analyze_variables.md | 152 ++++++++++++++++-- tests/testthat/_snaps/compare_variables.md | 18 ++- .../utils_default_stats_formats_labels.md | 8 +- 6 files changed, 167 insertions(+), 18 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5245331fab..9b797cf1d1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ * Added the `riskdiff` argument to `tabulate_rsp_subgroups` and `tabulate_survival_subgroups` to allow users to add a risk difference table column, and function `control_riskdiff` to specify settings for the risk difference column. * Added warning to `tabulate_rsp_subgroups` when `pval` statistic is selected but `df` has not been correctly generated to add p-values to the output table. * Added `n_rate` statistic as a non-default option to `estimate_incidence_rate` which returns both number of events observed and estimated incidence rate. +* Added `fraction` statistic to the `analyze_var_count` method group. ### Bug Fixes * Fixed a bug in `a_surv_time` that threw an error when split only has `"is_event"`. diff --git a/R/analyze_variables.R b/R/analyze_variables.R index 6f6a212131..69e0041607 100644 --- a/R/analyze_variables.R +++ b/R/analyze_variables.R @@ -310,6 +310,10 @@ s_summary.factor <- function(x, c(x, ifelse(dn > 0, x / dn, 0)) } ) + y$fraction <- lapply( + y$count, + function(count) c("num" = count, "denom" = dn) + ) y$n_blq <- sum(grepl("BLQ|LTR|<[1-9]|