Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand get_stats to cover all analysis functions #1123

Merged
merged 19 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export(tabulate_survival_biomarkers)
export(tabulate_survival_subgroups)
export(tern_default_formats)
export(tern_default_labels)
export(tern_default_stats)
export(test_proportion_diff)
export(to_n)
export(to_string_matrix)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Added internal utility function `apply_auto_formatting` to check for `"auto"` formats and replace them with
implementation of `format_auto` in analyze functions.
* Added utility function `labels_use_control` to modify labels with control specifications.
* Added list containing default statistics for each method group, `tern_default_stats`.

### Enhancements
* Added `ref_group_coxph` parameter to `g_km` to specify the reference group used for pairwise Cox-PH calculations when `annot_coxph = TRUE`.
Expand Down
2 changes: 2 additions & 0 deletions R/abnormal.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' @param abnormal (named `list`)\cr list identifying the abnormal range level(s) in `var`. Defaults to
#' `list(Low = "LOW", High = "HIGH")` but you can also group different levels into the named list,
#' for example, `abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH"))`.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal")`
#' to see available statistics for this function.
#'
#' @note
#' * `count_abnormal()` only works with a single variable containing multiple abnormal levels.
Expand Down
2 changes: 2 additions & 0 deletions R/abnormal_by_baseline.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#'
#' @inheritParams argument_convention
#' @param abnormal (`character`)\cr identifying the abnormal range level(s) in `.var`.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal_by_baseline")`
#' to see available statistics for this function.
#'
#' @note
#' * `df` should be filtered to include only post-baseline records.
Expand Down
2 changes: 2 additions & 0 deletions R/abnormal_by_marked.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' @inheritParams argument_convention
#' @param category (`list`)\cr with different marked category names for single
#' and last or replicated.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal_by_marked")`
#' to see available statistics for this function.
#'
#' @note `Single, not last` and `Last or replicated` levels are mutually exclusive. If a patient has
#' abnormalities that meet both the `Single, not last` and `Last or replicated` criteria, then the
Expand Down
2 changes: 2 additions & 0 deletions R/abnormal_by_worst_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#' * `Any`: Numerator is number of patients with at least one abnormality, which means grade is different from 0.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal_by_worst_grade")`
#' to see available statistics for this function.
#'
#' @details The pre-processing steps are crucial when using this function. From the standard lab grade variable
#' `ATOXGR`, derive the following two variables:
Expand Down
2 changes: 2 additions & 0 deletions R/abnormal_by_worst_grade_worsen.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' Patient count and fraction for laboratory events (worsen from baseline) shift table.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal_by_worst_grade_worsen")`
#' to see all available statistics.
#'
#' @seealso Relevant helper functions [h_adlb_worsen()] and [h_worsen_counter()]
#'
Expand Down
3 changes: 3 additions & 0 deletions R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ control_summarize_vars <- control_analyze_vars
#' functions; in this case [rtables::analyze()].
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("analyze_vars_numeric")` to see
#' statistics available for numeric variables, and `get_stats("analyze_vars_counts")` for statistics available
#' for non-numeric variables.
#'
#' @name analyze_variables
NULL
Expand Down
3 changes: 3 additions & 0 deletions R/compare_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#' Comparison with a reference group for different `x` objects.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("analyze_vars_numeric")` to see
#' statistics available for numeric variables, and `get_stats("analyze_vars_counts")` for statistics available
#' for non-numeric variables.
#'
#' @note
#' * For factor variables, `denom` for factor proportions can only be `n` since the purpose is to compare proportions
Expand Down
2 changes: 2 additions & 0 deletions R/count_cumulative.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#'
#' @inheritParams h_count_cumulative
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_cumulative")`
#' to see available statistics for this function.
#'
#' @seealso Relevant helper function [h_count_cumulative()], and descriptive function [d_count_cumulative()].
#'
Expand Down
2 changes: 2 additions & 0 deletions R/count_missed_doses.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' mainly the special labels.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_missed_doses")`
#' to see available statistics for this function.
#'
#' @seealso Relevant description function [d_count_missed_doses()].
#'
Expand Down
2 changes: 2 additions & 0 deletions R/count_occurrences.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' counted only once.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_occurrences")`
#' to see available statistics for this function.
#'
#' @note By default, occurrences which don't appear in a given row split are dropped from the table and
#' the occurrences in the table are sorted alphabetically per row split. Therefore, the corresponding layout
Expand Down
2 changes: 2 additions & 0 deletions R/count_occurrences_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' @param grade_groups (named `list` of `character`)\cr containing groupings of grades.
#' @param remove_single (`logical`)\cr `TRUE` to not include the elements of one-element grade groups
#' in the the output list; in this case only the grade groups names will be included in the output.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_occurrences_by_grade")`
#' to see available statistics for this function.
#'
#' @seealso Relevant helper function [h_append_grade_groups()].
#'
Expand Down
3 changes: 3 additions & 0 deletions R/count_patients_events_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#' when a column table layout is required.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run
#' `get_stats("summarize_patients_events_in_cols")` to see available statistics for this function, in addition to any
#' added using `filters_list`.
#'
#' @name count_patients_events_in_cols
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/count_patients_with_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' The primary analysis variable `.var` denotes the unique patient identifier.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_patients_with_event")`
#' to see available statistics for this function.
#'
#' @seealso [count_patients_with_flags]
#'
Expand Down
2 changes: 2 additions & 0 deletions R/count_patients_with_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' The primary analysis variable `.var` denotes the unique patient identifier.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_patients_with_flags")`
#' to see available statistics for this function.
#'
#' @seealso [count_patients_with_event]
#'
Expand Down
2 changes: 2 additions & 0 deletions R/count_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' We can count the occurrence of specific values in a variable of interest.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_values")`
#' to see available statistics for this function.
#'
#' @note
#' * For `factor` variables, `s_count_values` checks whether `values` are all included in the levels of `x`
Expand Down
2 changes: 2 additions & 0 deletions R/estimate_multinomial_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' regarding the level of a factor.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("estimate_multinomial_response")`
#' to see available statistics for this function.
#'
#' @seealso Relevant description function [d_onco_rsp_label()].
#'
Expand Down
2 changes: 2 additions & 0 deletions R/estimate_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' Estimate the proportion of responders within a studied population.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("estimate_proportion")`
#' to see available statistics for this function.
#'
#' @seealso [h_proportions]
#'
Expand Down
2 changes: 2 additions & 0 deletions R/incidence_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' indicating time unit for data input.
#' * `num_pt_year` (`numeric`)\cr time unit for desired output (in person-years).
#' @param n_events (`integer`)\cr number of events observed.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("estimate_incidence_rate")`
#' to see available statistics for this function.
#'
#' @seealso [control_incidence_rate()] and helper functions [h_incidence_rate].
#'
Expand Down
2 changes: 2 additions & 0 deletions R/odds_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' along with a confidence interval.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("estimate_odds_ratio")`
#' to see available statistics for this function.
#'
#' @details This function uses either logistic regression for unstratified
#' analyses, or conditional logistic regression for stratified analyses.
Expand Down
2 changes: 2 additions & 0 deletions R/prop_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#' @description `r lifecycle::badge("stable")`
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("estimate_proportion_diff")`
#' to see available statistics for this function.
#'
#' @seealso [d_proportion_diff()]
#'
Expand Down
2 changes: 2 additions & 0 deletions R/prop_diff_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' Various tests were implemented to test the difference between two proportions.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("test_proportion_diff")`
#' to see available statistics for this function.
#'
#' @seealso [h_prop_diff_test]
#'
Expand Down
2 changes: 1 addition & 1 deletion R/response_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ tabulate_rsp_biomarkers <- function(df,
checkmate::assert_data_frame(df)
checkmate::assert_character(df$biomarker)
checkmate::assert_character(df$biomarker_label)
checkmate::assert_subset(vars, c("n_tot", "n_rsp", "prop", "or", "ci", "pval"))
checkmate::assert_subset(vars, get_stats("tabulate_rsp_biomarkers"))
edelarua marked this conversation as resolved.
Show resolved Hide resolved

df_subs <- split(df, f = df$biomarker)
tabs <- lapply(df_subs, FUN = function(df_sub) {
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_ancova.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' multiple timepoints within the same response variable `.var`.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("summarize_ancova")`
#' to see available statistics for this function.
#'
#' @name summarize_ancova
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_change.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' or the change from baseline values (post-baseline) are then summarized.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("analyze_vars_numeric)`
#' to see available statistics for this function.
#'
#' @name summarize_change
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_coxreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' Fits a Cox regression model and estimates hazard ratio to describe the effect size in a survival analysis.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("summarize_coxreg")`
#' to see available statistics for this function.
#'
#' @details Cox models are the most commonly used methods to estimate the magnitude of
#' the effect in survival analysis. It assumes proportional hazards: the ratio
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_glm_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' This can be used to analyze count and/or frequency data using a linear model.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("summarize_glm_count")`
#' to see available statistics for this function.
#'
#' @name summarize_glm_count
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_num_patients.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' `nonunique` records.
#' @param unique_count_suffix (`logical`)\cr should `"(n)"` suffix be added to `unique_count` labels.
#' Defaults to `TRUE`.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("summarize_num_patients")`
#' to see available statistics for this function.
#'
#' @name summarize_num_patients
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_patients_exposure_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' when a column table layout is required.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run
#' `get_stats("analyze_patients_exposure_in_cols")` to see available statistics for this function.
#'
#' @name summarize_patients_exposure_in_cols
NULL
Expand Down
2 changes: 1 addition & 1 deletion R/survival_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ tabulate_survival_biomarkers <- function(df,
checkmate::assert_data_frame(df)
checkmate::assert_character(df$biomarker)
checkmate::assert_character(df$biomarker_label)
checkmate::assert_subset(vars, c("n_tot", "n_tot_events", "median", "hr", "ci", "pval"))
checkmate::assert_subset(vars, get_stats("tabulate_survival_biomarkers"))

df_subs <- split(df, f = df$biomarker)
tabs <- lapply(df_subs, FUN = function(df_sub) {
Expand Down
2 changes: 2 additions & 0 deletions R/survival_coxph_pairwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' * `ties` (`string`)\cr specifying the method for tie handling. Default is `"efron"`,
#' can also be set to `"breslow"` or `"exact"`. See more in [survival::coxph()]
#' * `conf_level` (`proportion`)\cr confidence level of the interval for HR.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("coxph_pairwise")`
#' to see available statistics for this function.
#'
#' @name survival_coxph_pairwise
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/survival_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#' * `conf_type` (`string`)\cr confidence interval type. Options are "plain" (default), "log", or "log-log",
#' see more in [survival::survfit()]. Note option "none" is not supported.
#' * `quantiles` (`numeric`)\cr vector of length two to specify the quantiles of survival time.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("surv_time")`
#' to see available statistics for this function.
#'
#' @name survival_time
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/survival_timepoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' * `conf_type` (`string`)\cr confidence interval type. Options are "plain" (default), "log", "log-log",
#' see more in [survival::survfit()]. Note option "none" is no longer supported.
#' * `time_point` (`number`)\cr survival time point of interest.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("surv_timepoint")`
#' to see available statistics for this function.
#'
#' @name survival_timepoint
NULL
Expand Down
Loading