From 0f2f5ea0622171c8c83be7ab338abd4496c16d58 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 9 Oct 2024 15:40:27 -0400 Subject: [PATCH 1/2] Fix bug in `a_summary()` causing nonunique row_names --- NEWS.md | 3 + R/analyze_variables.R | 2 +- tests/testthat/_snaps/analyze_variables.md | 342 ++++++++++----------- 3 files changed, 175 insertions(+), 172 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2948281da6..927bba96c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # tern 0.9.6.9004 +### Bug Fixes +* Fixed bug in `a_summary()` causing nonunique `row_name` values to occur when multiple statistics are selected for count variables. + # tern 0.9.6 ### Enhancements diff --git a/R/analyze_variables.R b/R/analyze_variables.R index 69e0041607..1711b8a126 100644 --- a/R/analyze_variables.R +++ b/R/analyze_variables.R @@ -531,7 +531,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 diff --git a/tests/testthat/_snaps/analyze_variables.md b/tests/testthat/_snaps/analyze_variables.md index 65f42acee6..f367f7e1ad 100644 --- a/tests/testthat/_snaps/analyze_variables.md +++ b/tests/testthat/_snaps/analyze_variables.md @@ -1033,31 +1033,31 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 10 0 n - 2 Sum 1.3 0 Sum - 3 Mean 0.1 0 Mean - 4 SD 0.8 0 SD - 5 SE 0.2 0 SE - 6 Mean (SD) 0.1 (0.8) 0 Mean (SD) - 7 Mean (SE) 0.1 (0.2) 0 Mean (SE) - 8 Mean 95% CI (-0.43, 0.69) 0 Mean 95% CI - 9 Mean -/+ 1xSE (-0.11, 0.38) 0 Mean -/+ 1xSE - 10 Mean -/+ 1xSD (-0.65, 0.91) 0 Mean -/+ 1xSD - 11 Mean p-value (H0: mean = 0) 0.6052 0 Mean p-value (H0: mean = 0) - 12 Median 0.3 0 Median - 13 Median Absolute Deviation -0.0 0 Median Absolute Deviation - 14 Median 95% CI (-0.82, 0.74) 0 Median 95% CI - 15 25% and 75%-ile -0.6 - 0.6 0 25% and 75%-ile - 16 IQR 1.2 0 IQR - 17 Min - Max -0.8 - 1.6 0 Min - Max - 18 Minimum -0.8 0 Minimum - 19 Maximum 1.6 0 Maximum - 20 Median (Min - Max) 0.3 (-0.8 - 1.6) 0 Median (Min - Max) - 21 CV (%) 590.4 0 CV (%) - 22 Geometric Mean NA 0 Geometric Mean - 23 Geometric Mean 95% CI NA 0 Geometric Mean 95% CI - 24 CV % Geometric Mean NA 0 CV % Geometric Mean + row_name formatted_cell indent_mod row_label + 1 n 10 0 n + 2 sum 1.3 0 Sum + 3 mean 0.1 0 Mean + 4 sd 0.8 0 SD + 5 se 0.2 0 SE + 6 mean_sd 0.1 (0.8) 0 Mean (SD) + 7 mean_se 0.1 (0.2) 0 Mean (SE) + 8 mean_ci (-0.43, 0.69) 0 Mean 95% CI + 9 mean_sei (-0.11, 0.38) 0 Mean -/+ 1xSE + 10 mean_sdi (-0.65, 0.91) 0 Mean -/+ 1xSD + 11 mean_pval 0.6052 0 Mean p-value (H0: mean = 0) + 12 median 0.3 0 Median + 13 mad -0.0 0 Median Absolute Deviation + 14 median_ci (-0.82, 0.74) 0 Median 95% CI + 15 quantiles -0.6 - 0.6 0 25% and 75%-ile + 16 iqr 1.2 0 IQR + 17 range -0.8 - 1.6 0 Min - Max + 18 min -0.8 0 Minimum + 19 max 1.6 0 Maximum + 20 median_range 0.3 (-0.8 - 1.6) 0 Median (Min - Max) + 21 cv 590.4 0 CV (%) + 22 geom_mean NA 0 Geometric Mean + 23 geom_mean_ci NA 0 Geometric Mean 95% CI + 24 geom_cv NA 0 CV % Geometric Mean --- @@ -1066,21 +1066,21 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 5 0 n - 2 a 3 0 a - 3 b 1 0 b - 4 c 1 0 c - 5 a 3 (60%) 0 a - 6 b 1 (20%) 0 b - 7 c 1 (20%) 0 c - 8 a 3 (60.0%) 0 a - 9 b 1 (20.0%) 0 b - 10 c 1 (20.0%) 0 c - 11 a 3/5 (60.0%) 0 a - 12 b 1/5 (20.0%) 0 b - 13 c 1/5 (20.0%) 0 c - 14 n_blq 0 0 n_blq + row_name formatted_cell indent_mod row_label + 1 n 5 0 n + 2 count.a 3 0 a + 3 count.b 1 0 b + 4 count.c 1 0 c + 5 count_fraction.a 3 (60%) 0 a + 6 count_fraction.b 1 (20%) 0 b + 7 count_fraction.c 1 (20%) 0 c + 8 count_fraction_fixed_dp.a 3 (60.0%) 0 a + 9 count_fraction_fixed_dp.b 1 (20.0%) 0 b + 10 count_fraction_fixed_dp.c 1 (20.0%) 0 c + 11 fraction.a 3/5 (60.0%) 0 a + 12 fraction.b 1/5 (20.0%) 0 b + 13 fraction.c 1/5 (20.0%) 0 c + 14 n_blq 0 0 n_blq --- @@ -1089,21 +1089,21 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 4 0 n - 2 A 2 0 A - 3 B 1 0 B - 4 C 1 0 C - 5 A 2 (50%) 0 A - 6 B 1 (25%) 0 B - 7 C 1 (25%) 0 C - 8 A 2 (50.0%) 0 A - 9 B 1 (25.0%) 0 B - 10 C 1 (25.0%) 0 C - 11 A 2/4 (50.0%) 0 A - 12 B 1/4 (25.0%) 0 B - 13 C 1/4 (25.0%) 0 C - 14 n_blq 0 0 n_blq + row_name formatted_cell indent_mod row_label + 1 n 4 0 n + 2 count.A 2 0 A + 3 count.B 1 0 B + 4 count.C 1 0 C + 5 count_fraction.A 2 (50%) 0 A + 6 count_fraction.B 1 (25%) 0 B + 7 count_fraction.C 1 (25%) 0 C + 8 count_fraction_fixed_dp.A 2 (50.0%) 0 A + 9 count_fraction_fixed_dp.B 1 (25.0%) 0 B + 10 count_fraction_fixed_dp.C 1 (25.0%) 0 C + 11 fraction.A 2/4 (50.0%) 0 A + 12 fraction.B 1/4 (25.0%) 0 B + 13 fraction.C 1/4 (25.0%) 0 C + 14 n_blq 0 0 n_blq --- @@ -1112,13 +1112,13 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 5 0 n - 2 count 3 0 count - 3 count_fraction 3 (60%) 0 count_fraction - 4 count_fraction 3 (60.0%) 0 count_fraction - 5 fraction 0 fraction - 6 n_blq 0 0 n_blq + row_name formatted_cell indent_mod row_label + 1 n 5 0 n + 2 count 3 0 count + 3 count_fraction 3 (60%) 0 count_fraction + 4 count_fraction_fixed_dp 3 (60.0%) 0 count_fraction + 5 fraction 0 fraction + 6 n_blq 0 0 n_blq # a_summary works with custom input. @@ -1127,9 +1127,9 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 std. dev 1 3 std. dev - 2 Median 95% CI -0.62 - 1.12 3 Median 95% CI + row_name formatted_cell indent_mod row_label + 1 sd 1 3 std. dev + 2 median_ci -0.62 - 1.12 3 Median 95% CI --- @@ -1138,25 +1138,25 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 number of records 5.00 -1 number of records - 2 a 2 5 a - 3 b 1 5 b - 4 c 1 5 c - 5 NA 1 5 NA - 6 a 2 (40%) 0 a - 7 b 1 (20%) 0 b - 8 c 1 (20%) 0 c - 9 NA 1 (20%) 0 NA - 10 a 2 (40.0%) 0 a - 11 b 1 (20.0%) 0 b - 12 c 1 (20.0%) 0 c - 13 NA 1 (20.0%) 0 NA - 14 a 2/5 (40.0%) 0 a - 15 b 1/5 (20.0%) 0 b - 16 c 1/5 (20.0%) 0 c - 17 NA 1/5 (20.0%) 0 NA - 18 n_blq 0 0 n_blq + row_name formatted_cell indent_mod row_label + 1 n 5.00 -1 number of records + 2 count.a 2 5 a + 3 count.b 1 5 b + 4 count.c 1 5 c + 5 count.NA 1 5 NA + 6 count_fraction.a 2 (40%) 0 a + 7 count_fraction.b 1 (20%) 0 b + 8 count_fraction.c 1 (20%) 0 c + 9 count_fraction.NA 1 (20%) 0 NA + 10 count_fraction_fixed_dp.a 2 (40.0%) 0 a + 11 count_fraction_fixed_dp.b 1 (20.0%) 0 b + 12 count_fraction_fixed_dp.c 1 (20.0%) 0 c + 13 count_fraction_fixed_dp.NA 1 (20.0%) 0 NA + 14 fraction.a 2/5 (40.0%) 0 a + 15 fraction.b 1/5 (20.0%) 0 b + 16 fraction.c 1/5 (20.0%) 0 c + 17 fraction.NA 1/5 (20.0%) 0 NA + 18 n_blq 0 0 n_blq # a_summary works with healthy input when compare = TRUE. @@ -1165,32 +1165,32 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 10 0 n - 2 Sum 51.3 0 Sum - 3 Mean 5.1 0 Mean - 4 SD 0.8 0 SD - 5 SE 0.2 0 SE - 6 Mean (SD) 5.1 (0.8) 0 Mean (SD) - 7 Mean (SE) 5.1 (0.2) 0 Mean (SE) - 8 Mean 95% CI (4.57, 5.69) 0 Mean 95% CI - 9 Mean -/+ 1xSE (4.89, 5.38) 0 Mean -/+ 1xSE - 10 Mean -/+ 1xSD (4.35, 5.91) 0 Mean -/+ 1xSD - 11 Mean p-value (H0: mean = 0) <0.0001 0 Mean p-value (H0: mean = 0) - 12 Median 5.3 0 Median - 13 Median Absolute Deviation -0.0 0 Median Absolute Deviation - 14 Median 95% CI (4.18, 5.74) 0 Median 95% CI - 15 25% and 75%-ile 4.4 - 5.6 0 25% and 75%-ile - 16 IQR 1.2 0 IQR - 17 Min - Max 4.2 - 6.6 0 Min - Max - 18 Minimum 4.2 0 Minimum - 19 Maximum 6.6 0 Maximum - 20 Median (Min - Max) 5.3 (4.2 - 6.6) 0 Median (Min - Max) - 21 CV (%) 15.2 0 CV (%) - 22 Geometric Mean 5.1 0 Geometric Mean - 23 Geometric Mean 95% CI (4.56, 5.66) 0 Geometric Mean 95% CI - 24 CV % Geometric Mean 15.2 0 CV % Geometric Mean - 25 p-value (t-test) <0.0001 0 p-value (t-test) + row_name formatted_cell indent_mod row_label + 1 n 10 0 n + 2 sum 51.3 0 Sum + 3 mean 5.1 0 Mean + 4 sd 0.8 0 SD + 5 se 0.2 0 SE + 6 mean_sd 5.1 (0.8) 0 Mean (SD) + 7 mean_se 5.1 (0.2) 0 Mean (SE) + 8 mean_ci (4.57, 5.69) 0 Mean 95% CI + 9 mean_sei (4.89, 5.38) 0 Mean -/+ 1xSE + 10 mean_sdi (4.35, 5.91) 0 Mean -/+ 1xSD + 11 mean_pval <0.0001 0 Mean p-value (H0: mean = 0) + 12 median 5.3 0 Median + 13 mad -0.0 0 Median Absolute Deviation + 14 median_ci (4.18, 5.74) 0 Median 95% CI + 15 quantiles 4.4 - 5.6 0 25% and 75%-ile + 16 iqr 1.2 0 IQR + 17 range 4.2 - 6.6 0 Min - Max + 18 min 4.2 0 Minimum + 19 max 6.6 0 Maximum + 20 median_range 5.3 (4.2 - 6.6) 0 Median (Min - Max) + 21 cv 15.2 0 CV (%) + 22 geom_mean 5.1 0 Geometric Mean + 23 geom_mean_ci (4.56, 5.66) 0 Geometric Mean 95% CI + 24 geom_cv 15.2 0 CV % Geometric Mean + 25 pval <0.0001 0 p-value (t-test) --- @@ -1199,22 +1199,22 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 5 0 n - 2 a 3 0 a - 3 b 1 0 b - 4 c 1 0 c - 5 a 3 (60%) 0 a - 6 b 1 (20%) 0 b - 7 c 1 (20%) 0 c - 8 a 3 (60.0%) 0 a - 9 b 1 (20.0%) 0 b - 10 c 1 (20.0%) 0 c - 11 a 3/5 (60.0%) 0 a - 12 b 1/5 (20.0%) 0 b - 13 c 1/5 (20.0%) 0 c - 14 n_blq 0 0 n_blq - 15 p-value (chi-squared test) 0.9560 0 p-value (chi-squared test) + row_name formatted_cell indent_mod row_label + 1 n 5 0 n + 2 count.a 3 0 a + 3 count.b 1 0 b + 4 count.c 1 0 c + 5 count_fraction.a 3 (60%) 0 a + 6 count_fraction.b 1 (20%) 0 b + 7 count_fraction.c 1 (20%) 0 c + 8 count_fraction_fixed_dp.a 3 (60.0%) 0 a + 9 count_fraction_fixed_dp.b 1 (20.0%) 0 b + 10 count_fraction_fixed_dp.c 1 (20.0%) 0 c + 11 fraction.a 3/5 (60.0%) 0 a + 12 fraction.b 1/5 (20.0%) 0 b + 13 fraction.c 1/5 (20.0%) 0 c + 14 n_blq 0 0 n_blq + 15 pval_counts 0.9560 0 p-value (chi-squared test) --- @@ -1223,22 +1223,22 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 4 0 n - 2 A 2 0 A - 3 B 1 0 B - 4 C 1 0 C - 5 A 2 (50%) 0 A - 6 B 1 (25%) 0 B - 7 C 1 (25%) 0 C - 8 A 2 (50.0%) 0 A - 9 B 1 (25.0%) 0 B - 10 C 1 (25.0%) 0 C - 11 A 2/4 (50.0%) 0 A - 12 B 1/4 (25.0%) 0 B - 13 C 1/4 (25.0%) 0 C - 14 n_blq 0 0 n_blq - 15 p-value (chi-squared test) 0.9074 0 p-value (chi-squared test) + row_name formatted_cell indent_mod row_label + 1 n 4 0 n + 2 count.A 2 0 A + 3 count.B 1 0 B + 4 count.C 1 0 C + 5 count_fraction.A 2 (50%) 0 A + 6 count_fraction.B 1 (25%) 0 B + 7 count_fraction.C 1 (25%) 0 C + 8 count_fraction_fixed_dp.A 2 (50.0%) 0 A + 9 count_fraction_fixed_dp.B 1 (25.0%) 0 B + 10 count_fraction_fixed_dp.C 1 (25.0%) 0 C + 11 fraction.A 2/4 (50.0%) 0 A + 12 fraction.B 1/4 (25.0%) 0 B + 13 fraction.C 1/4 (25.0%) 0 C + 14 n_blq 0 0 n_blq + 15 pval_counts 0.9074 0 p-value (chi-squared test) --- @@ -1247,14 +1247,14 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 n 5 0 n - 2 count 3 0 count - 3 count_fraction 3 (60%) 0 count_fraction - 4 count_fraction 3 (60.0%) 0 count_fraction - 5 fraction 0 fraction - 6 n_blq 0 0 n_blq - 7 p-value (chi-squared test) 0.8091 0 p-value (chi-squared test) + row_name formatted_cell indent_mod row_label + 1 n 5 0 n + 2 count 3 0 count + 3 count_fraction 3 (60%) 0 count_fraction + 4 count_fraction_fixed_dp 3 (60.0%) 0 count_fraction + 5 fraction 0 fraction + 6 n_blq 0 0 n_blq + 7 pval_counts 0.8091 0 p-value (chi-squared test) # a_summary works with custom input when compare = TRUE. @@ -1263,9 +1263,9 @@ Output RowsVerticalSection (in_rows) object print method: ---------------------------- - row_name formatted_cell indent_mod row_label - 1 pvalue <0.0001 3 pvalue - 2 Median 95% CI -0.41 - 1.10 3 Median 95% CI + row_name formatted_cell indent_mod row_label + 1 pval <0.0001 3 pvalue + 2 median_ci -0.41 - 1.10 3 Median 95% CI --- @@ -1275,25 +1275,25 @@ RowsVerticalSection (in_rows) object print method: ---------------------------- row_name formatted_cell indent_mod row_label - 1 number of records 5.00 -1 number of records - 2 a 2 5 a - 3 b 1 5 b - 4 c 1 5 c - 5 NA 1 5 NA - 6 a 2 (40%) 0 a - 7 b 1 (20%) 0 b - 8 c 1 (20%) 0 c - 9 NA 1 (20%) 0 NA - 10 a 2 (40.0%) 0 a - 11 b 1 (20.0%) 0 b - 12 c 1 (20.0%) 0 c - 13 NA 1 (20.0%) 0 NA - 14 a 2/5 (40.0%) 0 a - 15 b 1/5 (20.0%) 0 b - 16 c 1/5 (20.0%) 0 c - 17 NA 1/5 (20.0%) 0 NA + 1 n 5.00 -1 number of records + 2 count.a 2 5 a + 3 count.b 1 5 b + 4 count.c 1 5 c + 5 count.NA 1 5 NA + 6 count_fraction.a 2 (40%) 0 a + 7 count_fraction.b 1 (20%) 0 b + 8 count_fraction.c 1 (20%) 0 c + 9 count_fraction.NA 1 (20%) 0 NA + 10 count_fraction_fixed_dp.a 2 (40.0%) 0 a + 11 count_fraction_fixed_dp.b 1 (20.0%) 0 b + 12 count_fraction_fixed_dp.c 1 (20.0%) 0 c + 13 count_fraction_fixed_dp.NA 1 (20.0%) 0 NA + 14 fraction.a 2/5 (40.0%) 0 a + 15 fraction.b 1/5 (20.0%) 0 b + 16 fraction.c 1/5 (20.0%) 0 c + 17 fraction.NA 1/5 (20.0%) 0 NA 18 n_blq 0 0 n_blq - 19 p-value (chi-squared test) 0.8254 0 p-value (chi-squared test) + 19 pval_counts 0.8254 0 p-value (chi-squared test) # `analyze_vars` works with healthy input, default `na.rm = TRUE`. From ad6046ae06f4c677f86c294c1e4654e68631b6e8 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 9 Oct 2024 15:54:55 -0400 Subject: [PATCH 2/2] Fix spelling --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 927bba96c7..86088c20b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # tern 0.9.6.9004 ### Bug Fixes -* Fixed bug in `a_summary()` causing nonunique `row_name` values to occur when multiple statistics are selected for count variables. +* 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