Skip to content

Commit

Permalink
update name of new stats according to suggestion median_long into med…
Browse files Browse the repository at this point in the history
…ian_ci_3d
  • Loading branch information
iaugusty committed Oct 14, 2024
1 parent e7bfd91 commit 620f068
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 85 deletions.
12 changes: 6 additions & 6 deletions R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ s_summary.numeric <- function(x,
mean_sdi <- y$mean[[1]] + c(-1, 1) * stats::sd(x, na.rm = FALSE)
names(mean_sdi) <- c("mean_sdi_lwr", "mean_sdi_upr")
y$mean_sdi <- formatters::with_label(mean_sdi, "Mean -/+ 1xSD")
mean_long <- c(y$mean, y$mean_ci)
y$mean_long <- formatters::with_label(mean_long, paste0("Mean (", f_conf_level(control$conf_level), ")"))
mean_ci_3d <- c(y$mean, y$mean_ci)
y$mean_ci_3d <- formatters::with_label(mean_ci_3d, paste0("Mean (", f_conf_level(control$conf_level), ")"))

mean_pval <- stat_mean_pval(x, test_mean = control$test_mean, na.rm = FALSE, n_min = 2)
y$mean_pval <- formatters::with_label(mean_pval, paste("Mean", f_pval(control$test_mean)))
Expand All @@ -201,8 +201,8 @@ s_summary.numeric <- function(x,
median_ci <- stat_median_ci(x, conf_level = control$conf_level, na.rm = FALSE, gg_helper = FALSE)
y$median_ci <- formatters::with_label(median_ci, paste("Median", f_conf_level(control$conf_level)))

median_long <- c(y$median, median_ci)
y$median_long <- formatters::with_label(median_long, paste0("Median (", f_conf_level(control$conf_level), ")"))
median_ci_3d <- c(y$median, median_ci)
y$median_ci_3d <- formatters::with_label(median_ci_3d, paste0("Median (", f_conf_level(control$conf_level), ")"))

q <- control$quantiles
if (any(is.na(x))) {
Expand Down Expand Up @@ -236,8 +236,8 @@ s_summary.numeric <- function(x,

y$geom_cv <- c("geom_cv" = sqrt(exp(stats::sd(log(x_no_negative_vals), na.rm = FALSE) ^ 2) - 1) * 100) # styler: off

geom_mean_long <- c(y$geom_mean, y$geom_mean_ci)
y$geom_mean_long <- formatters::with_label(geom_mean_long, paste0("Geometric Mean (", f_conf_level(control$conf_level), ")"))
geom_mean_ci_3d <- c(y$geom_mean, y$geom_mean_ci)
y$geom_mean_ci_3d <- formatters::with_label(geom_mean_ci_3d, paste0("Geometric Mean (", f_conf_level(control$conf_level), ")"))

y
}
Expand Down
8 changes: 4 additions & 4 deletions R/survival_coxph_pairwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ s_coxph_pairwise <- function(df,
pvalue = formatters::with_label("", paste0("p-value (", pval_method, ")")),
hr = formatters::with_label("", "Hazard Ratio"),
hr_ci = formatters::with_label("", f_conf_level(conf_level)),
hr_long = formatters::with_label("", paste0("Hazard Ratio (", f_conf_level(conf_level), ")")),
hr_ci_3d = formatters::with_label("", paste0("Hazard Ratio (", f_conf_level(conf_level), ")")),
n_tot = formatters::with_label("", "Total n"),
n_tot_events = formatters::with_label("", "Total events")
)
Expand Down Expand Up @@ -112,7 +112,7 @@ s_coxph_pairwise <- function(df,
pvalue = formatters::with_label(unname(pval), paste0("p-value (", pval_method, ")")),
hr = formatters::with_label(sum_cox$conf.int[1, 1], "Hazard Ratio"),
hr_ci = formatters::with_label(unname(sum_cox$conf.int[1, 3:4]), f_conf_level(conf_level)),
hr_long = formatters::with_label(
hr_ci_3d = formatters::with_label(
c(sum_cox$conf.int[1, 1], unname(sum_cox$conf.int[1, 3:4])),
paste0("Hazard Ratio (", f_conf_level(conf_level), ")")
),
Expand All @@ -129,12 +129,12 @@ s_coxph_pairwise <- function(df,
#' @keywords internal
a_coxph_pairwise <- make_afun(
s_coxph_pairwise,
.indent_mods = c(pvalue = 0L, hr = 0L, hr_ci = 1L, n_tot = 0L, n_tot_events = 0L, hr_long = 0L),
.indent_mods = c(pvalue = 0L, hr = 0L, hr_ci = 1L, n_tot = 0L, n_tot_events = 0L, hr_ci_3d = 0L),
.formats = c(
pvalue = "x.xxxx | (<0.0001)",
hr = "xx.xx",
hr_ci = "(xx.xx, xx.xx)",
hr_long = "xx.xx (xx.xx - xx.xx)",
hr_ci_3d = "xx.xx (xx.xx - xx.xx)",
n_tot = "xx.xx",
n_tot_events = "xx.xx"
)
Expand Down
8 changes: 4 additions & 4 deletions R/survival_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NULL
#' * `s_surv_time()` returns the statistics:
#' * `median`: Median survival time.
#' * `median_ci`: Confidence interval for median time.
#' * `median_long`: Median with confidence interval for median time.
#' * `median_ci_3d`: Median with confidence interval for median time.
#' * `quantiles`: Survival time for two specified quantiles.
#' * `quantiles_lower`: quantile with confidence interval for the first specified quantile.
#' * `quantiles_upper`: quantile with confidence interval for the second specified quantile.
Expand Down Expand Up @@ -102,7 +102,7 @@ s_surv_time <- function(df,
range_censor = formatters::with_label(range_censor, "Range (censored)"),
range_event = formatters::with_label(range_event, "Range (event)"),
range = formatters::with_label(range, "Range"),
median_long = formatters::with_label(
median_ci_3d = formatters::with_label(
c(
unname(srv_tab["median"]),
unname(srv_tab[paste0(srv_fit$conf.int, c("LCL", "UCL"))])
Expand Down Expand Up @@ -153,12 +153,12 @@ a_surv_time <- function(df,
# Use method-specific defaults
fmts <- c(
median_ci = "(xx.x, xx.x)", quantiles = "xx.x, xx.x", range = "xx.x to xx.x",
median_long = "xx.x (xx.x - xx.x)",
median_ci_3d = "xx.x (xx.x - xx.x)",
quantiles_lower = "xx.x (xx.x - xx.x)", quantiles_upper = "xx.x (xx.x - xx.x)"
)
lbls <- c(
median_ci = "95% CI", range = "Range", range_censor = "Range (censored)", range_event = "Range (event)",
median_long = "Median (95% CI)",
median_ci_3d = "Median (95% CI)",
quantiles_lower = "25%-ile (95% CI)",
quantiles_upper = "75%-ile (95% CI)"
)
Expand Down
24 changes: 12 additions & 12 deletions R/survival_timepoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NULL
#' * `event_free_rate`: Event-free rate (%).
#' * `rate_se`: Standard error of event free rate.
#' * `rate_ci`: Confidence interval for event free rate.
#' * `event_free_rate_long`: Event-free rate (%) with Confidence interval.
#' * `event_free_rate_3d`: Event-free rate (%) with Confidence interval.
#'
#' @keywords internal
s_surv_timepoint <- function(df,
Expand Down Expand Up @@ -74,14 +74,14 @@ s_surv_timepoint <- function(df,
rate_se <- df_srv_fit$std.err
rate_ci <- c(df_srv_fit$lower, df_srv_fit$upper)
}
event_free_rate_long <- c(event_free_rate, rate_ci)
event_free_rate_3d <- c(event_free_rate, rate_ci)
list(
pt_at_risk = formatters::with_label(pt_at_risk, "Patients remaining at risk"),
event_free_rate = formatters::with_label(event_free_rate * 100, "Event Free Rate (%)"),
rate_se = formatters::with_label(rate_se * 100, "Standard Error of Event Free Rate"),
rate_ci = formatters::with_label(rate_ci * 100, f_conf_level(conf_level)),
event_free_rate_long = formatters::with_label(
event_free_rate_long * 100, paste0("Event Free Rate (", f_conf_level(conf_level), ")")
event_free_rate_3d = formatters::with_label(
event_free_rate_3d * 100, paste0("Event Free Rate (", f_conf_level(conf_level), ")")
)
)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ a_surv_timepoint <- make_afun(
#' * `s_surv_timepoint_diff()` returns the statistics:
#' * `rate_diff`: Event-free rate difference between two groups.
#' * `rate_diff_ci`: Confidence interval for the difference.
#' * `rate_diff_long`: Event-free rate difference and confidence interval between two groups.
#' * `rate_diff_ci_3d`: Event-free rate difference and confidence interval between two groups.
#' * `ztest_pval`: p-value to test the difference is 0.
#'
#' @keywords internal
Expand All @@ -131,7 +131,7 @@ s_surv_timepoint_diff <- function(df,
list(
rate_diff = formatters::with_label("", "Difference in Event Free Rate"),
rate_diff_ci = formatters::with_label("", f_conf_level(control$conf_level)),
rate_diff_long = formatters::with_label(
rate_diff_ci_3d = formatters::with_label(
"", paste0("Difference in Event Free Rate", f_conf_level(control$conf_level))
),
ztest_pval = formatters::with_label("", "p-value (Z-test)")
Expand All @@ -151,7 +151,7 @@ s_surv_timepoint_diff <- function(df,

qs <- c(-1, 1) * stats::qnorm(1 - (1 - control$conf_level) / 2)
rate_diff_ci <- rate_diff + qs * se_diff
rate_diff_long <- c(rate_diff, rate_diff_ci)
rate_diff_ci_3d <- c(rate_diff, rate_diff_ci)
ztest_pval <- if (is.na(rate_diff)) {
NA
} else {
Expand All @@ -160,8 +160,8 @@ s_surv_timepoint_diff <- function(df,
list(
rate_diff = formatters::with_label(rate_diff, "Difference in Event Free Rate"),
rate_diff_ci = formatters::with_label(rate_diff_ci, f_conf_level(control$conf_level)),
rate_diff_long = formatters::with_label(
rate_diff_long, paste0("Difference in Event Free Rate", f_conf_level(control$conf_level))
rate_diff_ci_3d = formatters::with_label(
rate_diff_ci_3d, paste0("Difference in Event Free Rate", f_conf_level(control$conf_level))
),
ztest_pval = formatters::with_label(ztest_pval, "p-value (Z-test)")
)
Expand All @@ -179,7 +179,7 @@ a_surv_timepoint_diff <- make_afun(
.formats = c(
rate_diff = "xx.xx",
rate_diff_ci = "(xx.xx, xx.xx)",
rate_diff_long = format_xx("xx.xx (xx.xx, xx.xx)"),
rate_diff_ci_3d = format_xx("xx.xx (xx.xx, xx.xx)"),
ztest_pval = "x.xxxx | (<0.0001)"
)
)
Expand Down Expand Up @@ -273,8 +273,8 @@ surv_timepoint <- function(lyt,
extra_args <- list(time_point = time_point, is_event = is_event, control = control, ...)

f <- list(
surv = c("pt_at_risk", "event_free_rate", "rate_se", "rate_ci", "event_free_rate_long"),
surv_diff = c("rate_diff", "rate_diff_ci", "ztest_pval", "rate_diff_long")
surv = c("pt_at_risk", "event_free_rate", "rate_se", "rate_ci", "event_free_rate_3d"),
surv_diff = c("rate_diff", "rate_diff_ci", "ztest_pval", "rate_diff_ci_3d")
)
.stats <- h_split_param(.stats, .stats, f = f)
.formats <- h_split_param(.formats, names(.formats), f = f)
Expand Down
20 changes: 10 additions & 10 deletions R/utils_default_stats_formats_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ tern_default_stats <- list(
"n", "sum", "mean", "sd", "se", "mean_sd", "mean_se", "mean_ci", "mean_sei", "mean_sdi", "mean_pval",
"median", "mad", "median_ci", "quantiles", "iqr", "range", "min", "max", "median_range", "cv",
"geom_mean", "geom_mean_ci", "geom_cv",
"median_long",
"mean_long", "geom_mean_long"
"median_ci_3d",
"mean_ci_3d", "geom_mean_ci_3d"
),
count_cumulative = c("count_fraction", "count_fraction_fixed_dp"),
count_missed_doses = c("n", "count_fraction", "count_fraction_fixed_dp"),
Expand All @@ -409,12 +409,12 @@ tern_default_stats <- list(
summarize_num_patients = c("unique", "nonunique", "unique_count"),
summarize_patients_events_in_cols = c("unique", "all"),
surv_time = c(
"median", "median_ci", "median_long", "quantiles",
"median", "median_ci", "median_ci_3d", "quantiles",
"quantiles_lower", "quantiles_upper", "range_censor", "range_event", "range"
),
surv_timepoint = c(
"pt_at_risk", "event_free_rate", "rate_se", "rate_ci", "rate_diff", "rate_diff_ci", "ztest_pval",
"event_free_rate_long"
"event_free_rate_3d"
),
tabulate_rsp_biomarkers = c("n_tot", "n_rsp", "prop", "or", "ci", "pval"),
tabulate_rsp_subgroups = c("n", "n_rsp", "prop", "n_tot", "or", "ci", "pval"),
Expand Down Expand Up @@ -450,11 +450,11 @@ tern_default_formats <- c(
mean_sei = "(xx.xx, xx.xx)",
mean_sdi = "(xx.xx, xx.xx)",
mean_pval = "x.xxxx | (<0.0001)",
mean_long = "xx.xx (xx.xx - xx.xx)",
mean_ci_3d = "xx.xx (xx.xx - xx.xx)",
median = "xx.x",
mad = "xx.x",
median_ci = "(xx.xx, xx.xx)",
median_long = "xx.xx (xx.xx - xx.xx)",
median_ci_3d = "xx.xx (xx.xx - xx.xx)",
quantiles = "xx.x - xx.x",
quantiles_lower = "xx.xx (xx.xx - xx.xx)",
quantiles_upper = "xx.xx (xx.xx - xx.xx)",
Expand All @@ -466,7 +466,7 @@ tern_default_formats <- c(
cv = "xx.x",
geom_mean = "xx.x",
geom_mean_ci = "(xx.xx, xx.xx)",
geom_mean_long = "xx.xx (xx.xx - xx.xx)",
geom_mean_ci_3d = "xx.xx (xx.xx - xx.xx)",
geom_cv = "xx.x",
pval = "x.xxxx | (<0.0001)",
pval_counts = "x.xxxx | (<0.0001)",
Expand Down Expand Up @@ -504,11 +504,11 @@ tern_default_labels <- c(
mean_sei = "Mean -/+ 1xSE",
mean_sdi = "Mean -/+ 1xSD",
mean_pval = "Mean p-value (H0: mean = 0)",
mean_long = "Mean (95% CI)",
mean_ci_3d = "Mean (95% CI)",
median = "Median",
mad = "Median Absolute Deviation",
median_ci = "Median 95% CI",
median_long = "Median (95% CI)",
median_ci_3d = "Median (95% CI)",
quantiles = "25% and 75%-ile",
quantiles_lower = "25%-ile (95% CI)",
quantiles_upper = "75%-ile (95% CI)",
Expand All @@ -520,7 +520,7 @@ tern_default_labels <- c(
cv = "CV (%)",
geom_mean = "Geometric Mean",
geom_mean_ci = "Geometric Mean 95% CI",
geom_mean_long = "Geometric Mean (95% CI)",
geom_mean_ci_3d = "Geometric Mean (95% CI)",
geom_cv = "CV % Geometric Mean",
pval = "p-value (t-test)", # Default for numeric
pval_counts = "p-value (chi-squared test)", # Default for counts
Expand Down
30 changes: 15 additions & 15 deletions tests/testthat/_snaps/analyze_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
attr(,"label")
[1] "Mean -/+ 1xSD"
$mean_long
$mean_ci_3d
mean mean_ci_lwr mean_ci_upr
NA NA NA
attr(,"label")
Expand Down Expand Up @@ -77,7 +77,7 @@
attr(,"label")
[1] "Median 95% CI"
$median_long
$median_ci_3d
median median_ci_lwr median_ci_upr
NA NA NA
attr(,"label")
Expand Down Expand Up @@ -129,7 +129,7 @@
geom_cv
NA
$geom_mean_long
$geom_mean_ci_3d
geom_mean mean_ci_lwr mean_ci_upr
NaN NA NA
attr(,"label")
Expand Down Expand Up @@ -187,7 +187,7 @@
attr(,"label")
[1] "Mean -/+ 1xSD"
$mean_long
$mean_ci_3d
mean mean_ci_lwr mean_ci_upr
1 NA NA
attr(,"label")
Expand Down Expand Up @@ -215,7 +215,7 @@
attr(,"label")
[1] "Median 95% CI"
$median_long
$median_ci_3d
median median_ci_lwr median_ci_upr
1 NA NA
attr(,"label")
Expand Down Expand Up @@ -267,7 +267,7 @@
geom_cv
NA
$geom_mean_long
$geom_mean_ci_3d
geom_mean mean_ci_lwr mean_ci_upr
1 NA NA
attr(,"label")
Expand Down Expand Up @@ -325,7 +325,7 @@
attr(,"label")
[1] "Mean -/+ 1xSD"
$mean_long
$mean_ci_3d
mean mean_ci_lwr mean_ci_upr
NA NA NA
attr(,"label")
Expand Down Expand Up @@ -353,7 +353,7 @@
attr(,"label")
[1] "Median 95% CI"
$median_long
$median_ci_3d
median median_ci_lwr median_ci_upr
NA NA NA
attr(,"label")
Expand Down Expand Up @@ -405,7 +405,7 @@
geom_cv
NA
$geom_mean_long
$geom_mean_ci_3d
geom_mean mean_ci_lwr mean_ci_upr
NA NA NA
attr(,"label")
Expand Down Expand Up @@ -463,7 +463,7 @@
attr(,"label")
[1] "Mean -/+ 1xSD"
$mean_long
$mean_ci_3d
mean mean_ci_lwr mean_ci_upr
1.500000 -4.853102 7.853102
attr(,"label")
Expand Down Expand Up @@ -491,7 +491,7 @@
attr(,"label")
[1] "Median 95% CI"
$median_long
$median_ci_3d
median median_ci_lwr median_ci_upr
1.5 NA NA
attr(,"label")
Expand Down Expand Up @@ -543,7 +543,7 @@
geom_cv
52.10922
$geom_mean_long
$geom_mean_ci_3d
geom_mean mean_ci_lwr mean_ci_upr
1.41421356 0.01729978 115.60839614
attr(,"label")
Expand Down Expand Up @@ -601,7 +601,7 @@
attr(,"label")
[1] "Mean -/+ 1xSD"
$mean_long
$mean_ci_3d
mean mean_ci_lwr mean_ci_upr
6.000000 3.318768 8.681232
attr(,"label")
Expand Down Expand Up @@ -629,7 +629,7 @@
attr(,"label")
[1] "Median 95% CI"
$median_long
$median_ci_3d
median median_ci_lwr median_ci_upr
6.5 1.0 10.0
attr(,"label")
Expand Down Expand Up @@ -681,7 +681,7 @@
geom_cv
96.61307
$geom_mean_long
$geom_mean_ci_3d
geom_mean mean_ci_lwr mean_ci_upr
4.842534 2.456211 9.547283
attr(,"label")
Expand Down
Loading

0 comments on commit 620f068

Please sign in to comment.