Skip to content

Commit

Permalink
Merge branch 'main' into 1301-feature-request-add-confidence-interval…
Browse files Browse the repository at this point in the history
…s-for-quantiles-in-surv_time
  • Loading branch information
shajoezhu authored Oct 23, 2024
2 parents 700fc94 + de68073 commit 11d7726
Show file tree
Hide file tree
Showing 77 changed files with 459 additions and 308 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
default_stages: [commit]
default_stages: [pre-commit]
default_language_version:
python: python3
repos:
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tern
Title: Create Common TLGs Used in Clinical Trials
Version: 0.9.6.9001
Date: 2024-09-30
Version: 0.9.6.9007
Date: 2024-10-20
Authors@R: c(
person("Joe", "Zhu", , "[email protected]", role = c("aut", "cre")),
person("Daniel", "Sabanés Bové", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -48,7 +48,7 @@ Imports:
rlang (>= 1.1.0),
scales (>= 1.2.0),
stats,
survival (>= 3.2-13),
survival (>= 3.6-4),
tibble (>= 2.0.0),
tidyr (>= 0.8.3),
utils
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# tern 0.9.6.9001
# tern 0.9.6.9007

### Bug Fixes
* Fixed bug in `a_summary()` causing non-unique `row_name` values to occur when multiple statistics are selected for count variables.

# tern 0.9.6

Expand All @@ -16,6 +19,7 @@
* Refactored `estimate_incidence_rate` to work as both an analyze function and a summarize function, controlled by the added `summarize` parameter. When `summarize = TRUE`, labels can be fine-tuned via the new `label_fmt` argument to the same function.
* Added `fraction` statistic to the `analyze_var_count` method group.
* Improved `summarize_glm_count()` documentation and all its associated functions to better describe the results and the functions' purpose.
* Added `method` argument to `s_odds_ratio()` and `estimate_odds_ratio()` to control whether exact or approximate conditional likelihood calculations are used.

### Bug Fixes
* Added defaults for `d_count_cumulative` parameters as described in the documentation.
Expand Down
5 changes: 3 additions & 2 deletions R/abnormal.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#' for example, `abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH"))`.
#' @param exclude_base_abn (`flag`)\cr whether to exclude subjects with baseline abnormality
#' from numerator and denominator.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("abnormal"))``
#'
#' @note
#' * `count_abnormal()` only considers a single variable that contains multiple abnormal levels.
Expand Down
5 changes: 3 additions & 2 deletions R/abnormal_by_baseline.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#'
#' @inheritParams argument_convention
#' @param abnormal (`character`)\cr values 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.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("abnormal_by_baseline"))``
#'
#' @note
#' * `df` should be filtered to include only post-baseline records.
Expand Down
5 changes: 3 additions & 2 deletions R/abnormal_by_marked.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#' @inheritParams argument_convention
#' @param category (`list`)\cr a list 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.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("abnormal_by_marked"))``
#'
#' @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
5 changes: 3 additions & 2 deletions R/abnormal_by_worst_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#' splits, one on variable `param` and one on variable `grade_dir`.
#'
#' @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.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("abnormal_by_worst_grade"))``
#'
#' @seealso [h_adlb_abnormal_by_worst_grade()] which pre-processes ADLB data frames to be used in
#' [count_abnormal_by_worst_grade()].
Expand Down
5 changes: 3 additions & 2 deletions R/abnormal_by_worst_grade_worsen.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#' * `id` (`string`)\cr subject variable name.
#' * `baseline_var` (`string`)\cr name of the data column containing baseline toxicity variable.
#' * `direction_var` (`string`)\cr see `direction_var` for more details.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("abnormal_by_worst_grade_worsen")`
#' to see all available statistics.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("abnormal_by_worst_grade_worsen"))``
#'
#' @seealso Relevant helper functions [h_adlb_worsen()] and [h_worsen_counter()] which are used within
#' [s_count_abnormal_lab_worsen_by_baseline()] to process input data.
Expand Down
10 changes: 6 additions & 4 deletions R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ control_analyze_vars <- function(conf_level = 0.95,
#' columns) will be considered (`.df_row[[.var]]`, see [`rtables::additional_fun_params`]) and not the whole dataset.
#'
#' @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.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options for numeric variables are: ``r shQuote(get_stats("analyze_vars_numeric"))``
#'
#' Options for non-numeric variables are: ``r shQuote(get_stats("analyze_vars_counts"))``
#'
#' @name analyze_variables
#' @order 1
Expand Down Expand Up @@ -539,7 +541,7 @@ a_summary <- function(x,
in_rows(
.list = x_stats,
.formats = .formats,
.names = .labels,
.names = names(.labels),
.labels = .labels,
.indent_mods = .indent_mods,
.format_na_strs = na_str
Expand Down
47 changes: 29 additions & 18 deletions R/bland_altman.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' Functions that use the Bland-Altman method to assess the agreement between two numerical vectors.
#' Statistics function that uses the Bland-Altman method to assess the agreement between two numerical vectors
#' and calculates a variety of statistics.
#'
#' @inheritParams argument_convention
#' @param y (`numeric`)\cr vector of numbers we want to analyze, to be compared with `x`.
#'
#' @name bland_altman
NULL

#' @describeIn bland_altman Statistics function that compares two numeric vectors using the Bland-Altman method
#' and calculates a variety of statistics.
#'
#' @return
#' * `s_bland_altman()` returns a named list of the following elements: `df`, `difference_mean`, `ci_mean`,
#' `difference_sd`, `difference_se`, `upper_agreement_limit`, `lower_agreement_limit`, `agreement_limit_se`,
#' `upper_agreement_limit_ci`, `lower_agreement_limit_ci`, `t_value`, and `n`.
#' A named list of the following elements:
#' * `df`
#' * `difference_mean`
#' * `ci_mean`
#' * `difference_sd`
#' * `difference_se`
#' * `upper_agreement_limit`
#' * `lower_agreement_limit`
#' * `agreement_limit_se`
#' * `upper_agreement_limit_ci`
#' * `lower_agreement_limit_ci`
#' * `t_value`
#' * `n`
#'
#' @examples
#' x <- seq(1, 60, 5)
#' y <- seq(5, 50, 4)
#' conf_level <- 0.9
#'
#' # Derive statistics that are needed for Bland-Altman plot
#' s_bland_altman(x, y, conf_level = conf_level)
#' s_bland_altman(x, y, conf_level = 0.9)
#'
#' @export
s_bland_altman <- function(x, y, conf_level = 0.95) {
Expand Down Expand Up @@ -75,16 +78,24 @@ s_bland_altman <- function(x, y, conf_level = 0.95) {
)
}

#' @describeIn bland_altman Graphing function that produces a Bland-Altman plot.
#' Bland-Altman plot
#'
#' @return
#' * `g_bland_altman()` returns a `ggplot` Bland-Altman plot.
#' @description `r lifecycle::badge("experimental")`
#'
#' Graphing function that produces a Bland-Altman plot.
#'
#' @inheritParams s_bland_altman
#'
#' @return A `ggplot` Bland-Altman plot.
#'
#' @examples
#' # Create a Bland-Altman plot
#' g_bland_altman(x = x, y = y, conf_level = conf_level)
#' x <- seq(1, 60, 5)
#' y <- seq(5, 50, 4)
#'
#' g_bland_altman(x = x, y = y, conf_level = 0.9)
#'
#' @export
#' @aliases bland_altman
g_bland_altman <- function(x, y, conf_level = 0.95) {
result_tem <- s_bland_altman(x, y, conf_level = conf_level)
xpos <- max(result_tem$df$average) * 0.9 + min(result_tem$df$average) * 0.1
Expand Down
8 changes: 5 additions & 3 deletions R/compare_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#' statistic.
#'
#' @inheritParams argument_convention
#' @param .stats (`character`)\cr statistics to select for the table. Run
#' `get_stats("analyze_vars_numeric", add_pval = TRUE)` to see statistics available for numeric variables, and
#' `get_stats("analyze_vars_counts", add_pval = TRUE)` for statistics available for non-numeric variables.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options for numeric variables are: ``r shQuote(get_stats("analyze_vars_numeric", add_pval = TRUE))``
#'
#' Options for non-numeric variables are: ``r shQuote(get_stats("analyze_vars_counts", add_pval = TRUE))``
#'
#' @note
#' * For factor variables, `denom` for factor proportions can only be `n` since the purpose is to compare proportions
Expand Down
5 changes: 3 additions & 2 deletions R/count_cumulative.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#' @inheritParams h_count_cumulative
#' @inheritParams argument_convention
#' @param thresholds (`numeric`)\cr vector of cutoff values for the counts.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_cumulative")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_cumulative"))``
#'
#' @seealso Relevant helper function [h_count_cumulative()], and descriptive function [d_count_cumulative()].
#'
Expand Down
5 changes: 3 additions & 2 deletions R/count_missed_doses.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#' @inheritParams s_count_cumulative
#' @inheritParams argument_convention
#' @param thresholds (`numeric`)\cr minimum number of missed doses the patients had.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_missed_doses")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_missed_doses"))``
#'
#' @seealso
#' * Relevant description function [d_count_missed_doses()] which generates labels for [count_missed_doses()].
Expand Down
5 changes: 3 additions & 2 deletions R/count_occurrences.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#' @inheritParams argument_convention
#' @param drop (`flag`)\cr whether non-appearing occurrence levels should be dropped from the resulting table.
#' Note that in that case the remaining occurrence levels in the table are sorted alphabetically.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_occurrences")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_occurrences"))``
#'
#' @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
5 changes: 3 additions & 2 deletions R/count_occurrences_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#' @param only_grade_groups (`flag`)\cr whether only the specified grade groups should be
#' included, with individual grade rows removed (`TRUE`), or all grades and grade groups
#' should be displayed (`FALSE`).
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_occurrences_by_grade")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_occurrences_by_grade"))``
#'
#' @seealso Relevant helper function [h_append_grade_groups()].
#'
Expand Down
7 changes: 4 additions & 3 deletions R/count_patients_events_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#' that corresponding table cells will stay blank.
#' @param custom_label (`string` or `NULL`)\cr if provided and `labelstr` is empty then this will
#' be used as label.
#' @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`.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' In addition to any statistics added using `filters_list`, statistic options are:
#' ``r shQuote(get_stats("summarize_patients_events_in_cols"))``
#'
#' @name count_patients_events_in_cols
#' @order 1
Expand Down
5 changes: 3 additions & 2 deletions R/count_patients_with_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#' Multiple column names and flags are accepted in this format
#' `c("column_name1" = "flag1", "column_name2" = "flag2")`.
#' Note that only equality is being accepted as condition.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_patients_with_event")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_patients_with_event"))``
#'
#' @seealso [count_patients_with_flags]
#'
Expand Down
5 changes: 3 additions & 2 deletions R/count_patients_with_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#' @param flag_variables (`character`)\cr a vector specifying the names of `logical` variables from analysis dataset
#' used for counting the number of unique identifiers.
#' @param flag_labels (`character`)\cr vector of labels to use for flag variables.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_patients_with_flags")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_patients_with_flags"))``
#'
#' @seealso [count_patients_with_event]
#'
Expand Down
5 changes: 3 additions & 2 deletions R/count_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#'
#' @inheritParams argument_convention
#' @param values (`character`)\cr specific values that should be counted.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("count_values")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("count_values"))``
#'
#' @note
#' * For `factor` variables, `s_count_values` checks whether `values` are all included in the levels of `x`
Expand Down
5 changes: 3 additions & 2 deletions R/estimate_multinomial_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#' `var`, should be a factor variable, the values of which will be used as labels within the output table.
#'
#' @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.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("estimate_multinomial_response"))``
#'
#' @seealso Relevant description function [d_onco_rsp_label()].
#'
Expand Down
5 changes: 3 additions & 2 deletions R/estimate_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#'
#' @inheritParams prop_strat_wilson
#' @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.
#' @param method (`string`)\cr the method used to construct the confidence interval
#' for proportion of successful outcomes; one of `waldcc`, `wald`, `clopper-pearson`,
#' `wilson`, `wilsonc`, `strat_wilson`, `strat_wilsonc`, `agresti-coull` or `jeffreys`.
#' @param long (`flag`)\cr whether a long description is required.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("estimate_proportion"))``
#'
#' @seealso [h_proportions]
#'
Expand Down
2 changes: 0 additions & 2 deletions R/formatting_functions.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#' Formatting functions
#'
#' @description `r lifecycle::badge("stable")`
#'
#' See below for the list of formatting functions created in `tern` to work with `rtables`.
#'
#' Other available formats can be listed via [`formatters::list_valid_format_labels()`]. Additional
Expand Down
5 changes: 3 additions & 2 deletions R/incidence_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#' @param n_events (`string`)\cr name of integer variable indicating whether an event has been observed (1) or not (0).
#' @param id_var (`string`)\cr name of variable used as patient identifier if `"n_unique"` is included in `.stats`.
#' Defaults to `"USUBJID"`.
#' @param .stats (`character`)\cr statistics to select for the table. Run `get_stats("estimate_incidence_rate")`
#' to see available statistics for this function.
#' @param .stats (`character`)\cr statistics to select for the table.
#'
#' Options are: ``r shQuote(get_stats("estimate_incidence_rate"))``
#' @param summarize (`flag`)\cr whether the function should act as an analyze function (`summarize = FALSE`), or a
#' summarize function (`summarize = TRUE`). Defaults to `FALSE`.
#' @param label_fmt (`string`)\cr how labels should be formatted after a row split occurs if `summarize = TRUE`. The
Expand Down
Loading

0 comments on commit 11d7726

Please sign in to comment.