From e7ddcf2ece2fc2d3bd3140509e792b3a88f89efb Mon Sep 17 00:00:00 2001 From: cf124952_gsk Date: Thu, 18 Jun 2026 12:34:10 +0100 Subject: [PATCH 1/3] fix bug in ci_prop_diff_mn_strata() when by is a character without specified levels Fixes #20 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/prop_ci_mn.R | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9c1eb3f..dde8b34 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: cicalc Title: Calculate Confidence Intervals -Version: 0.2.1 +Version: 0.2.2 Authors@R: c( person("Christina", "Fillmore", , "christina.e.fillmore@gsk.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0595-2302")), diff --git a/NEWS.md b/NEWS.md index 515922d..bcd4d06 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# cicalc 0.2.2 +* Fix issue with factor conversion in Miettinen-Nurminen CI calculation #20 + + # cicalc 0.2.1 * Fix bug in Miettinen-Nurminen CI calculation when non-rootable conditions occur diff --git a/R/prop_ci_mn.R b/R/prop_ci_mn.R index ab81978..2c5082c 100644 --- a/R/prop_ci_mn.R +++ b/R/prop_ci_mn.R @@ -419,7 +419,7 @@ ci_prop_diff_mn_strata <- function(x, by, strata, method = c("score", "summary s estimate_df <- dplyr::tibble( x = x, - by = as.numeric(as.factor(by)), + by = as.numeric(forcats::as_factor(by)), strata = strata ) |> dplyr::group_by(strata) |> From 0e1b40191fa252763b910c6e0e4d75d2ec9f76a6 Mon Sep 17 00:00:00 2001 From: cf124952_gsk Date: Thu, 18 Jun 2026 12:56:10 +0100 Subject: [PATCH 2/3] #21 fix bug --- NEWS.md | 2 +- R/prop_ci_common_risk.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index bcd4d06..b3d3c06 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # cicalc 0.2.2 * Fix issue with factor conversion in Miettinen-Nurminen CI calculation #20 - +* Fix issue with ci_prop_diff_mh_strata() for z statistic calculation # cicalc 0.2.1 * Fix bug in Miettinen-Nurminen CI calculation when non-rootable conditions occur diff --git a/R/prop_ci_common_risk.R b/R/prop_ci_common_risk.R index 330935c..c3c785a 100644 --- a/R/prop_ci_common_risk.R +++ b/R/prop_ci_common_risk.R @@ -127,7 +127,7 @@ ci_prop_diff_mh_strata <- function(x, by, strata, conf.level = 0.95, sato_var = lower_ci <- d_mh - z_alpha*sqrt(est_var) upper_ci <- d_mh + z_alpha*sqrt(est_var) - z_stat <- d_mh/sqrt(sato_var) + z_stat <- d_mh/sqrt(est_var) p.value <- 2 * (1 - stats::pnorm(abs(z_stat))) From 5868673d8734a903864dbb676ae4e8fc0bbef082 Mon Sep 17 00:00:00 2001 From: cf124952_gsk Date: Thu, 18 Jun 2026 13:14:01 +0100 Subject: [PATCH 3/3] Issues 22-24 --- NEWS.md | 2 ++ R/prop_ci.R | 2 +- R/prop_ci_common_risk.R | 8 +++++--- tests/testthat/_snaps/prop_ci_common_risk.md | 12 ++++++------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index b3d3c06..18c8374 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # cicalc 0.2.2 * Fix issue with factor conversion in Miettinen-Nurminen CI calculation #20 * Fix issue with ci_prop_diff_mh_strata() for z statistic calculation +* Fix issue with ci_prop_wilson_strata() when datasets are provided [#22](https://github.com/GSK-Biostatistics/cicalc/issues/22) +* Fix non-logical [#23](https://github.com/GSK-Biostatistics/cicalc/issues/23) and dataset issue [#24](https://github.com/GSK-Biostatistics/cicalc/issues/24) for ci_prop_diff_nc_strata() # cicalc 0.2.1 * Fix bug in Miettinen-Nurminen CI calculation when non-rootable conditions occur diff --git a/R/prop_ci.R b/R/prop_ci.R index 88bdb97..8c1ce7a 100644 --- a/R/prop_ci.R +++ b/R/prop_ci.R @@ -439,7 +439,7 @@ ci_prop_wilson_strata <- function(x, # if data was passed, evaluate in the context of the data frame if (is.data.frame(data)) { return( - ci_prop_jeffreys( + ci_prop_wilson_strata( x = x , conf.level = conf.level ) |> diff --git a/R/prop_ci_common_risk.R b/R/prop_ci_common_risk.R index c3c785a..9c34f62 100644 --- a/R/prop_ci_common_risk.R +++ b/R/prop_ci_common_risk.R @@ -334,9 +334,11 @@ ci_prop_diff_nc_strata <- function(x, # if data was passed, evaluate in the context of the data frame if (is.data.frame(data)) { return( - ci_prop_diff_nc( + ci_prop_diff_nc_strata( x = x, by = by, + strata = strata, + weights_method = weights_method, conf.level = conf.level, correct = correct ) |> @@ -353,7 +355,7 @@ ci_prop_diff_nc_strata <- function(x, check_scalar(correct) check_range(conf.level, range = c(0, 1), include_bounds = c(FALSE, FALSE)) check_scalar(conf.level) - + x<- as.logical(x) if (any(tapply(x, strata, length) < 5)) { cli::cli_warn("Less than 5 observations in some strata.") @@ -439,6 +441,6 @@ ci_prop_diff_nc_strata <- function(x, method = glue::glue("Stratified Newcombe Confidence Interval {ifelse(correct, 'with', 'without')} continuity correction, {weights_method}") ), - class = c("stratified_newcombe", "stratified_wilson", "cicada") + class = c("ci_prop_diff_nc_strata", "stratified_wilson", "cicalc") ) } diff --git a/tests/testthat/_snaps/prop_ci_common_risk.md b/tests/testthat/_snaps/prop_ci_common_risk.md index b5f1c66..2aa9bed 100644 --- a/tests/testthat/_snaps/prop_ci_common_risk.md +++ b/tests/testthat/_snaps/prop_ci_common_risk.md @@ -109,9 +109,9 @@ * 50 responses out of 80 * Weights: a.x = 0.211, b.x = 0.189, a.y = 0.118, b.y = 0.154, a.z = 0.174, b.z = 0.153 - * Estimate: 0 + * Estimate: 0.259 * 95% Confidence Interval: - (0, 0) + (0.0392, 0.4502) --- @@ -124,9 +124,9 @@ * 50 responses out of 80 * Weights: a.x = 0.195, b.x = 0.163, a.y = 0.135, b.y = 0.138, a.z = 0.202, b.z = 0.167 - * Estimate: 0 + * Estimate: 0.254 * 95% Confidence Interval: - (0, 0) + (0.0347, 0.4454) --- @@ -138,9 +138,9 @@ * 50 responses out of 80 * Weights: a.x = 0.211, b.x = 0.189, a.y = 0.118, b.y = 0.154, a.z = 0.174, b.z = 0.153 - * Estimate: 0 + * Estimate: 0.259 * 95% Confidence Interval: - (0, 0) + (0.0392, 0.4502) ---