Skip to content

Commit

Permalink
Merge branch 'main' into 1130_update_descs@main
Browse files Browse the repository at this point in the history
  • Loading branch information
ayogasekaram authored Sep 5, 2024
2 parents 4120fbb + f9fb467 commit a83862a
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 13 deletions.
4 changes: 2 additions & 2 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.5.9017
Date: 2024-09-04
Version: 0.9.5.9019
Date: 2024-09-05
Authors@R: c(
person("Joe", "Zhu", , "joe.zhu@roche.com", role = c("aut", "cre")),
person("Daniel", "Sabanés Bové", , "daniel.sabanes_bove@roche.com", role = "aut"),
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# tern 0.9.5.9017
# tern 0.9.5.9019
### Enhancements
* Added `errorbar_width` and `linetype` parameters to `g_lineplot`.
* Reworking of `summarize_glm_count()` documentation and all its associated functions to better describe the results and the functions' purpose.
* Added the `.formats` argument to `tabulate_rsp_subgroups` and `tabulate_survival_subgroups` to allow users to specify formats.
* 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.

### Bug Fixes
* Fixed a bug in `a_surv_time` that threw an error when split only has `"is_event"`.
Expand Down
2 changes: 1 addition & 1 deletion R/argument_convention.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#' for more information.
#' @param lyt (`PreDataTableLayouts`)\cr layout that analyses will be added to.
#' @param method (`string` or `NULL`)\cr specifies the test used to calculate the p-value for the difference between
#' two proportions. For options, see [s_test_proportion_diff()]. Default is `NULL` so no test is performed.
#' two proportions. For options, see [test_proportion_diff()]. Default is `NULL` so no test is performed.
#' @param na.rm (`flag`)\cr whether `NA` values should be removed from `x` prior to analysis.
#' @param na_str (`string`)\cr string used to replace all `NA` or empty values in the output.
#' @param nested (`flag`)\cr whether this layout instruction should be applied within the existing layout structure _if
Expand Down
12 changes: 9 additions & 3 deletions R/incidence_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ NULL
#' - `n_events`: Total number of events observed.
#' - `rate`: Estimated incidence rate.
#' - `rate_ci`: Confidence interval for the incidence rate.
#' - `n_rate`: Total number of events observed & estimated incidence rate.
#'
#' @keywords internal
s_incidence_rate <- function(df,
Expand Down Expand Up @@ -79,7 +80,11 @@ s_incidence_rate <- function(df,
person_years = formatters::with_label(person_years, "Total patient-years at risk"),
n_events = formatters::with_label(n_events, "Number of adverse events observed"),
rate = formatters::with_label(result$rate, paste("AE rate per", num_pt_year, "patient-years")),
rate_ci = formatters::with_label(result$rate_ci, f_conf_level(conf_level))
rate_ci = formatters::with_label(result$rate_ci, f_conf_level(conf_level)),
n_rate = formatters::with_label(
c(n_events, result$rate),
paste("Number of adverse events observed (AE rate per", num_pt_year, "patient-years)")
)
)
}

Expand All @@ -96,7 +101,8 @@ a_incidence_rate <- make_afun(
"person_years" = "xx.x",
"n_events" = "xx",
"rate" = "xx.xx",
"rate_ci" = "(xx.xx, xx.xx)"
"rate_ci" = "(xx.xx, xx.xx)",
"n_rate" = "xx (xx.x)"
)
)

Expand Down Expand Up @@ -144,7 +150,7 @@ estimate_incidence_rate <- function(lyt,
...,
show_labels = "hidden",
table_names = vars,
.stats = NULL,
.stats = c("person_years", "n_events", "rate", "rate_ci"),
.formats = NULL,
.labels = NULL,
.indent_mods = NULL) {
Expand Down
8 changes: 8 additions & 0 deletions R/response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ tabulate_rsp_subgroups <- function(lyt,
)) {
checkmate::assert_list(riskdiff, null.ok = TRUE)
checkmate::assert_true(all(c("n_tot", "or", "ci") %in% vars))
if ("pval" %in% vars && !"pval" %in% names(df$or)) {
warning(
'The "pval" statistic has been selected but is not present in "df" so it will not be included in the output ',
'table. To include the "pval" statistic, please specify a p-value test when generating "df" via ',
'the "method" argument to `extract_rsp_subgroups()`. If method = "cmh", strata must also be specified via the ',
'"variables" argument to `extract_rsp_subgroups()`.'
)
}

# Create "ci" column from "lcl" and "ucl"
df$or$ci <- combine_vectors(df$or$lcl, df$or$ucl)
Expand Down
2 changes: 1 addition & 1 deletion R/utils_default_stats_formats_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ tern_default_stats <- list(
count_patients_with_flags = c("n", "count", "count_fraction", "count_fraction_fixed_dp", "n_blq"),
count_values = c("n", "count", "count_fraction", "count_fraction_fixed_dp", "n_blq"),
coxph_pairwise = c("pvalue", "hr", "hr_ci", "n_tot", "n_tot_events"),
estimate_incidence_rate = c("person_years", "n_events", "rate", "rate_ci"),
estimate_incidence_rate = c("person_years", "n_events", "rate", "rate_ci", "n_rate"),
estimate_multinomial_response = c("n_prop", "prop_ci"),
estimate_odds_ratio = c("or_ci", "n_tot"),
estimate_proportion = c("n_prop", "prop_ci"),
Expand Down
2 changes: 1 addition & 1 deletion man/argument_convention.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/d_rsp_subgroups_colvars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/extract_rsp_subgroups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/h_response_subgroups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/incidence_rate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/testthat/_snaps/estimate_incidence_rate.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
attr(,"label")
[1] "90% CI"
$n_rate
[1] 4.00000 44.15823
attr(,"label")
[1] "Number of adverse events observed (AE rate per 100 patient-years)"

# estimate_incidence_rate works as expected with healthy input

Expand All @@ -115,3 +120,15 @@
AE rate per 100 patient-years 26.20 57.23
90% CI (5.06, 135.73) (22.14, 147.94)

# estimate_incidence_rate `n_rate` statistic works as expected

Code
res
Output
A B
(N=3) (N=3)
—————————————————————————————————————————————————————————————————————————————————————
Number of adverse events observed 1 3
AE rate per 100 patient-years 2.18 4.77
Number of adverse events observed (AE rate per 100 patient-years) 1 (2.2) 3 (4.8)

24 changes: 24 additions & 0 deletions tests/testthat/test-estimate_incidence_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,27 @@ testthat::test_that("estimate_incidence_rate works as expected with healthy inpu
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("estimate_incidence_rate `n_rate` statistic works as expected", {
df <- data.frame(
USUBJID = as.character(seq(6)),
CNSR = c(0, 1, 1, 0, 0, 0),
AVAL = c(10.1, 20.4, 15.3, 20.8, 18.7, 23.4),
ARM = factor(c("A", "A", "A", "B", "B", "B"))
) %>%
dplyr::mutate(is_event = CNSR == 0) %>%
dplyr::mutate(n_events = as.integer(is_event))

result <- basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
estimate_incidence_rate(
vars = "AVAL",
n_events = "n_events",
.stats = c("n_events", "rate", "n_rate")
) %>%
build_table(df)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})
21 changes: 21 additions & 0 deletions tests/testthat/test-response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,24 @@ testthat::test_that("tabulate_rsp_subgroups riskdiff argument works as expected"
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("tabulate_rsp_subgroups pval statistic warning works as expected", {
adrs <- adrs_200

df <- extract_rsp_subgroups(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "STRATA2")),
data = adrs,
method = NULL,
conf_level = 0.95
)

# warning when no pval in df
expect_warning(
basic_table() %>%
tabulate_rsp_subgroups(
df = df,
vars = c("n", "prop", "n_tot", "or", "ci", "pval")
),
"please specify a p-value test"
)
})

0 comments on commit a83862a

Please sign in to comment.