Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added "fraction" statistic to the "analyze_var_count" method group #1309

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* 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.
* Added `fraction` statistic to the `analyze_var_count` method group.

kpagacz marked this conversation as resolved.
Show resolved Hide resolved
### Bug Fixes
* Fixed a bug in `a_surv_time` that threw an error when split only has `"is_event"`.
Expand Down
4 changes: 4 additions & 0 deletions R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ s_summary.factor <- function(x,
c(x, ifelse(dn > 0, x / dn, 0))
}
)
y$fraction <- lapply(
y$count,
function(count) c("num" = count, "denom" = dn)
)

y$n_blq <- sum(grepl("BLQ|LTR|<[1-9]|<PCLLOQ", x))

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 @@ -368,7 +368,7 @@ tern_default_stats <- list(
abnormal_by_worst_grade = c("count_fraction", "count_fraction_fixed_dp"),
abnormal_by_worst_grade_worsen = c("fraction"),
analyze_patients_exposure_in_cols = c("n_patients", "sum_exposure"),
analyze_vars_counts = c("n", "count", "count_fraction", "count_fraction_fixed_dp", "n_blq"),
analyze_vars_counts = c("n", "count", "count_fraction", "count_fraction_fixed_dp", "fraction", "n_blq"),
analyze_vars_numeric = c(
"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",
Expand Down
152 changes: 140 additions & 12 deletions tests/testthat/_snaps/analyze_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,20 @@
[1] 4.0000000 0.4444444


$fraction
$fraction$Female
num denom
2 9

$fraction$Male
num denom
3 9

$fraction$Unknown
num denom
4 9


$n_blq
[1] 0

Expand Down Expand Up @@ -668,6 +682,24 @@
[1] 1.0000000 0.1428571


$fraction
$fraction$Female
num denom
2 7

$fraction$Male
num denom
2 7

$fraction$Unknown
num denom
2 7

$fraction$`NA`
num denom
1 7


$n_blq
[1] 0

Expand Down Expand Up @@ -702,6 +734,20 @@
[1] 4.0000000 0.4444444


$fraction
$fraction$Female
num denom
2 9

$fraction$Male
num denom
3 9

$fraction$Unknown
num denom
4 9


$n_blq
[1] 0

Expand Down Expand Up @@ -736,6 +782,20 @@
[1] 0 0


$fraction
$fraction$a
num denom
0 0

$fraction$b
num denom
0 0

$fraction$c
num denom
0 0


$n_blq
[1] 0

Expand Down Expand Up @@ -770,6 +830,20 @@
[1] 4.0 0.2


$fraction
$fraction$Female
num denom
2 20

$fraction$Male
num denom
3 20

$fraction$Unknown
num denom
4 20


$n_blq
[1] 0

Expand Down Expand Up @@ -804,6 +878,20 @@
[1] 4.0000000 0.1333333


$fraction
$fraction$Female
num denom
2 30

$fraction$Male
num denom
3 30

$fraction$Unknown
num denom
4 30


$n_blq
[1] 0

Expand Down Expand Up @@ -844,6 +932,24 @@
[1] 1.0 0.1


$fraction
$fraction$Female
num denom
2 10

$fraction$Male
num denom
3 10

$fraction$Unknown
num denom
4 10

$fraction$`NA`
num denom
1 10


$n_blq
[1] 0

Expand Down Expand Up @@ -971,7 +1077,10 @@
8 a 3 (60.0%) 0 a
9 b 1 (20.0%) 0 b
10 c 1 (20.0%) 0 c
11 n_blq 0 0 n_blq
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

---

Expand All @@ -991,7 +1100,10 @@
8 A 2 (50.0%) 0 A
9 B 1 (25.0%) 0 B
10 C 1 (25.0%) 0 C
11 n_blq 0 0 n_blq
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

---

Expand All @@ -1005,7 +1117,8 @@
2 count 3 0 count
3 count_fraction 3 (60%) 0 count_fraction
4 count_fraction 3 (60.0%) 0 count_fraction
5 n_blq 0 0 n_blq
5 fraction 0 fraction
6 n_blq 0 0 n_blq

# a_summary works with custom input.

Expand Down Expand Up @@ -1039,7 +1152,11 @@
11 b 1 (20.0%) 0 b
12 c 1 (20.0%) 0 c
13 NA 1 (20.0%) 0 NA
14 n_blq 0 0 n_blq
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

# a_summary works with healthy input when compare = TRUE.

Expand Down Expand Up @@ -1093,8 +1210,11 @@
8 a 3 (60.0%) 0 a
9 b 1 (20.0%) 0 b
10 c 1 (20.0%) 0 c
11 n_blq 0 0 n_blq
12 p-value (chi-squared test) 0.9560 0 p-value (chi-squared test)
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)

---

Expand All @@ -1114,8 +1234,11 @@
8 A 2 (50.0%) 0 A
9 B 1 (25.0%) 0 B
10 C 1 (25.0%) 0 C
11 n_blq 0 0 n_blq
12 p-value (chi-squared test) 0.9074 0 p-value (chi-squared test)
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)

---

Expand All @@ -1129,8 +1252,9 @@
2 count 3 0 count
3 count_fraction 3 (60%) 0 count_fraction
4 count_fraction 3 (60.0%) 0 count_fraction
5 n_blq 0 0 n_blq
6 p-value (chi-squared test) 0.8091 0 p-value (chi-squared test)
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)

# a_summary works with custom input when compare = TRUE.

Expand Down Expand Up @@ -1164,8 +1288,12 @@
11 b 1 (20.0%) 0 b
12 c 1 (20.0%) 0 c
13 NA 1 (20.0%) 0 NA
14 n_blq 0 0 n_blq
15 p-value (chi-squared test) 0.8254 0 p-value (chi-squared test)
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
19 p-value (chi-squared test) 0.8254 0 p-value (chi-squared test)

# `analyze_vars` works with healthy input, default `na.rm = TRUE`.

Expand Down
18 changes: 16 additions & 2 deletions tests/testthat/_snaps/compare_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
Code
res
Output
[1] "n" "count" "count_fraction" "n_blq"
[5] "pval_counts"
[1] "n" "count" "count_fraction" "fraction"
[5] "n_blq" "pval_counts"

---

Expand Down Expand Up @@ -75,6 +75,20 @@
[1] 1.0 0.2
$fraction
$fraction$a
num denom
3 5
$fraction$b
num denom
1 5
$fraction$c
num denom
1 5
$n_blq
[1] 0
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/_snaps/utils_default_stats_formats_labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Output
[1] "n" "count"
[3] "count_fraction" "count_fraction_fixed_dp"
[5] "n_blq"
[5] "fraction" "n_blq"

---

Expand Down Expand Up @@ -138,6 +138,8 @@
"n" "count"
count_fraction count_fraction_fixed_dp
"count_fraction" "count_fraction"
n_blq pval_counts
"n_blq" "p-value (chi-squared test)"
fraction n_blq
"fraction" "n_blq"
pval_counts
"p-value (chi-squared test)"

Loading