Skip to content

Commit 451efec

Browse files
authored
Merge pull request #99 from FredHutch/lemireg-add_quartiles-pairwise_test_cont
Adding median_quartiles to pairwise_test_cont()
2 parents e89fd2d + 2571a1e commit 451efec

File tree

7 files changed

+109
-54
lines changed

7 files changed

+109
-54
lines changed

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# VISCfunctions (development version)
22

3+
* Add `Median_Quartiles` to `pairwise_test_cont()` output (#99)
4+
* Minor Changes:
5+
* Update `Overview()` to include new `Median_Quartiles` (#99)
6+
37
# VISCfunctions 1.3.1
48

59
* Report loaded and attached packages in package reproducibility table (#132)
@@ -67,7 +71,7 @@
6771
* New Functions:
6872
* `escape()` to easily make latex friendly columns with `\` in front of special characters
6973
* `wilson_ci()` function for Wilson Confident Intervals
70-
* `pariwise_test_bin()` for pairwise binary testing comparisons (i.e. pairwise group differences in response rates)
74+
* `pairwise_test_bin()` for pairwise binary testing comparisons (i.e. pairwise group differences in response rates)
7175
* Minor Changes:
7276
* Adding suffix param to `stat_paste()`. Now easy to add % or something else after each stat, if needed
7377
* Improved documentation and minor fixes to `two_samp_cont_test()`

R/pairwise_comparisons.R

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ pairwise_test_cont <- function(
262262
Group2_median = 10^stats::median(log10(j_vals), na.rm = T),
263263
Group1_max = max(i_vals, na.rm = T),
264264
Group2_max = max(j_vals, na.rm = T),
265+
Group1_q1 = stats::quantile(i_vals, probs = c(.25), na.rm = T),
266+
Group2_q1 = stats::quantile(j_vals, probs = c(.25), na.rm = T),
267+
Group1_q3 = stats::quantile(i_vals, probs = c(.75), na.rm = T),
268+
Group2_q3 = stats::quantile(j_vals, probs = c(.75), na.rm = T),
265269
Group1_mean = 10^mean(log10(i_vals), na.rm = T),
266270
Group2_mean = 10^mean(log10(j_vals), na.rm = T),
267271
Group1log_mean = mean(log10(i_vals), na.rm = T),
@@ -283,6 +287,10 @@ pairwise_test_cont <- function(
283287
Group2_max = max(j_vals, na.rm = T),
284288
Group1_mean = mean(i_vals, na.rm = T),
285289
Group2_mean = mean(j_vals, na.rm = T),
290+
Group1_q1 = stats::quantile(i_vals, probs = c(.25), na.rm = T),
291+
Group2_q1 = stats::quantile(j_vals, probs = c(.25), na.rm = T),
292+
Group1_q3 = stats::quantile(i_vals, probs = c(.75), na.rm = T),
293+
Group2_q3 = stats::quantile(j_vals, probs = c(.75), na.rm = T),
286294
Group1_sd = stats::sd(i_vals, na.rm = T),
287295
Group2_sd = stats::sd(j_vals, na.rm = T)
288296
)
@@ -328,10 +336,9 @@ pairwise_test_cont <- function(
328336
if (length(results_list) == 0) return(NULL)
329337

330338
results <- do.call(base::rbind, results_list)
331-
332339
# Pasting together stats
333340
pasted_results <- paste_tbl_grp(
334-
data = results, vars_to_paste = c("n","median_min_max",'mean'),
341+
data = results, vars_to_paste = c("n","median_min_max",'mean', "median_quartiles"),
335342
first_name = 'Group1', second_name = 'Group2', sep_val = sep_val,
336343
alternative = alternative, digits = digits, trailing_zeros = trailing_zeros,
337344
keep_all = TRUE, verbose = verbose)
@@ -358,6 +365,7 @@ pairwise_test_cont <- function(
358365
Comparison = pasted_results$Comparison,
359366
SampleSizes = pasted_results$n_comparison,
360367
Median_Min_Max = pasted_results$median_min_max_comparison,
368+
Median_Quartiles = pasted_results$median_quartiles,
361369
Mean = pasted_results$mean_comparison,
362370
log_Mean_SD = pasted_results_extra$mean_sd_comparison,
363371
MagnitudeTest = results$MagnitudeTest,
@@ -383,6 +391,7 @@ pairwise_test_cont <- function(
383391
Comparison = pasted_results$Comparison,
384392
SampleSizes = pasted_results$n_comparison,
385393
Median_Min_Max = pasted_results$median_min_max_comparison,
394+
Median_Quartiles = pasted_results$median_quartiles_comparison,
386395
Mean_SD = pasted_results_extra$mean_sd_comparison,
387396
MagnitudeTest = results$MagnitudeTest,
388397
PerfectSeparation = results$PerfectSeparation,
@@ -774,10 +783,9 @@ pairwise_test_bin <- function(x,
774783
#' exampleData_BAMA |>
775784
#' filter(visitno != 0) |>
776785
#' group_by(group, visitno) |>
777-
#' summarize(
786+
#' reframe(
778787
#' cor_test_pairs(x = magnitude, pair = antigen, id = pubID,
779-
#' method = 'spearman', n_distinct_value = 3, digits = 1, verbose = TRUE),
780-
#' .groups = 'drop'
788+
#' method = 'spearman', n_distinct_value = 3, digits = 1, verbose = TRUE)
781789
#' )
782790
#'
783791
#' @export

R/pretty_output_functions.R

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Pasting Together Information for Two Groups
22
#'
3-
#' Paste together information, often statistics, from two groups. There are two
4-
#' predefined combinations: mean(sd) and median\[min, max\], but user may also
3+
#' Paste together information, often statistics, from two groups. There are three
4+
#' predefined combinations: mean(sd) and median\[min, max\] and median\[first quartile, third quartile\], but user may also
55
#' paste any single measure together.
66
#'
77
#'
@@ -32,7 +32,7 @@
3232
#' @param verbose a logical variable indicating if warnings and messages should be displayed. Default FALSE.
3333
#' @details
3434
#'
35-
#' User must use consistant naming throughout, with a underscore to separate the group names from the measures (i.e. `Group1_mean` and `Group2_mean`). There also must be columns defining the group names (i.e. `Group1` and `Group2`), which are used to form the `Comparison` variable.
35+
#' User must use consistent naming throughout, with a underscore to separate the group names from the measures (i.e. `Group1_mean` and `Group2_mean`). There also must be columns defining the group names (i.e. `Group1` and `Group2`), which are used to form the `Comparison` variable.
3636
#'
3737
#' `alternative` included as a parameter so the direction can easily be seen in one-sided test. If "two.sided" is selected the value to be pasted between the two group names will be set to `sep_val`, where "greater" will use " > " and "less" with use " < " as the pasting value.
3838
#'
@@ -137,6 +137,9 @@ paste_tbl_grp <- function(
137137
vars_to_paste_here <- c(vars_to_paste_here, 'median_min_max')
138138
if (sum(vars_to_paste_here %in% c('mean','sd')) == 2)
139139
vars_to_paste_here <- c(vars_to_paste_here, 'mean_sd')
140+
if (sum(vars_to_paste_here %in% c('median','q1','q3')) == 3)
141+
vars_to_paste_here <- c(vars_to_paste_here, 'median_quartiles')
142+
140143

141144
if (verbose) message('The following measures will be combined: ',
142145
paste0(vars_to_paste_here, collapse = ', '))
@@ -151,11 +154,14 @@ paste_tbl_grp <- function(
151154

152155
# Need to define which variables to check. Special considerations for the predefined values
153156
vars_to_check <- vars_to_paste_here[!vars_to_paste_here %in%
154-
c('median_min_max','mean_sd')]
157+
c('median_min_max','median_quartiles','mean_sd')]
155158
if (any(vars_to_paste_here == 'median_min_max'))
156159
vars_to_check <- unique(c(vars_to_check, 'median', 'min', 'max'))
157160
if (any(vars_to_paste_here == 'mean_sd'))
158161
vars_to_check <- unique(c(vars_to_check, 'mean', 'sd'))
162+
if (any(vars_to_paste_here == 'median_quartiles'))
163+
vars_to_check <- unique(c(vars_to_check, 'median', 'q1','q3'))
164+
159165

160166
# Need to check the group1 and group2 version of each variable being pasted
161167
group1_vars_to_check <- paste0(first_name, '_', vars_to_check)
@@ -223,7 +229,23 @@ paste_tbl_grp <- function(
223229
trailing_zeros = trailing_zeros
224230
)
225231
)
226-
} else {
232+
} else if (vars_to_paste_here[i] == 'median_quartiles') {
233+
pasted_results[[i]] <- paste0(
234+
stat_paste(stat1 = data_here[, paste0(first_name, '_median')],
235+
stat2 = data_here[, paste0(first_name, '_q1')],
236+
stat3 = data_here[, paste0(first_name, '_q3')],
237+
digits = digits, bound_char = '[', sep = ', ',
238+
na_str_out = na_str_out, trailing_zeros = trailing_zeros
239+
),
240+
sep_val,
241+
stat_paste(stat1 = data_here[, paste0(second_name, '_median')],
242+
stat2 = data_here[, paste0(second_name, '_q1')],
243+
stat3 = data_here[, paste0(second_name, '_q3')],
244+
digits = digits, bound_char = '[', sep = ', ',
245+
na_str_out = na_str_out, trailing_zeros = trailing_zeros
246+
)
247+
)
248+
} else {
227249
first_var_here <- data_here[, paste0(first_name, '_', vars_to_paste_here[i])]
228250
second_var_here <- data_here[, paste0(second_name, '_', vars_to_paste_here[i])]
229251
both_var_here <- c(first_var_here, second_var_here)

man/cor_test_pairs.Rd

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/paste_tbl_grp.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)