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

Adding n to the proportion_ci*() results #260

Merged
merged 5 commits into from
Feb 10, 2025
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 DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Suggests:
survival (>= 3.6-4),
testthat (>= 3.2.0),
withr (>= 2.5.0)
Remotes: insightsengineering/cards
Config/Needs/website: insightsengineering/nesttemplate
Config/testthat/edition: 3
Config/testthat/parallel: true
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cardx 0.2.2.9017

* Little `n` is now returned with the results of the `proportion_ci_*()` functions, which then flows into the results of `ard_proportion_ci()`. (#256)

* Update in `ard_categorical.survey.design()` for factor variables that are all missing. These variables can now be tabulated, where previously this resulted in an error.

* Update in `ard_missing.survey.design()` where we can now tabulate the missing rate of design variables, such as the weights.
Expand Down
12 changes: 10 additions & 2 deletions R/proportion_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ proportion_ci_wald <- function(x, conf.level = 0.95, correct = FALSE) {

list(
N = n,
n = sum(x),
estimate = p_hat,
conf.low = l_ci,
conf.high = u_ci,
Expand Down Expand Up @@ -90,7 +91,11 @@ proportion_ci_wilson <- function(x, conf.level = 0.95, correct = FALSE) {
n <- length(x)
y <- stats::prop.test(x = sum(x), n = n, correct = correct, conf.level = conf.level)

list(N = n, conf.level = conf.level) |>
list(
N = n,
n = sum(x),
conf.level = conf.level
) |>
utils::modifyList(val = broom::tidy(y) |> as.list()) |>
utils::modifyList(
list(
Expand Down Expand Up @@ -126,7 +131,7 @@ proportion_ci_clopper_pearson <- function(x, conf.level = 0.95) {

y <- stats::binom.test(x = sum(x), n = n, conf.level = conf.level)

list(N = n, conf.level = conf.level) |>
list(N = n, n = sum(x), conf.level = conf.level) |>
utils::modifyList(val = broom::tidy(y) |> as.list()) |>
utils::modifyList(list(method = "Clopper-Pearson Confidence Interval"))
}
Expand Down Expand Up @@ -168,6 +173,7 @@ proportion_ci_agresti_coull <- function(x, conf.level = 0.95) {

list(
N = n,
n = sum(x),
estimate = mean(x),
conf.low = l_ci,
conf.high = u_ci,
Expand Down Expand Up @@ -211,6 +217,7 @@ proportion_ci_jeffreys <- function(x, conf.level = 0.95) {

list(
N = n,
n = sum(x),
estimate = mean(x),
conf.low = l_ci,
conf.high = u_ci,
Expand Down Expand Up @@ -351,6 +358,7 @@ proportion_ci_strat_wilson <- function(x,
# Return values
list(
N = length(x),
n = sum(x),
estimate = mean(x),
conf.low = lower,
conf.high = upper,
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gtsummary
mmrm
pre
quosures
renv
rlang's
sd
unlist
Expand Down
26 changes: 14 additions & 12 deletions tests/testthat/_snaps/ard_proportion_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
Code
ard_categorical_ci_strat_wilson
Message
{cards} data frame: 6 x 9
{cards} data frame: 7 x 9
Output
variable variable_level context stat_name stat_label stat
1 rsp TRUE proporti… N N 80
2 rsp TRUE proporti… estimate estimate 0.625
3 rsp TRUE proporti… conf.low conf.low 0.487
4 rsp TRUE proporti… conf.high conf.high 0.719
5 rsp TRUE proporti… conf.level conf.lev… 0.95
6 rsp TRUE proporti… method method Stratifi…
2 rsp TRUE proporti… n n 50
3 rsp TRUE proporti… estimate estimate 0.625
4 rsp TRUE proporti… conf.low conf.low 0.487
5 rsp TRUE proporti… conf.high conf.high 0.719
6 rsp TRUE proporti… conf.level conf.lev… 0.95
7 rsp TRUE proporti… method method Stratifi…
Message
i 3 more variables: fmt_fn, warning, error

Expand All @@ -20,15 +21,16 @@
Code
ard_categorical_ci_strat_wilsoncc
Message
{cards} data frame: 6 x 9
{cards} data frame: 7 x 9
Output
variable variable_level context stat_name stat_label stat
1 rsp TRUE proporti… N N 80
2 rsp TRUE proporti… estimate estimate 0.625
3 rsp TRUE proporti… conf.low conf.low 0.448
4 rsp TRUE proporti… conf.high conf.high 0.753
5 rsp TRUE proporti… conf.level conf.lev… 0.95
6 rsp TRUE proporti… method method Stratifi…
2 rsp TRUE proporti… n n 50
3 rsp TRUE proporti… estimate estimate 0.625
4 rsp TRUE proporti… conf.low conf.low 0.448
5 rsp TRUE proporti… conf.high conf.high 0.753
6 rsp TRUE proporti… conf.level conf.lev… 0.95
7 rsp TRUE proporti… method method Stratifi…
Message
i 3 more variables: fmt_fn, warning, error

Expand Down
57 changes: 57 additions & 0 deletions tests/testthat/_snaps/proportion_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
$N
[1] 10

$n
[1] 5

$conf.level
[1] 0.9

Expand Down Expand Up @@ -60,6 +63,9 @@
$N
[1] 32

$n
[1] 32

$conf.level
[1] 0.95

Expand Down Expand Up @@ -99,6 +105,9 @@
$N
[1] 32

$n
[1] 0

$conf.level
[1] 0.95

Expand Down Expand Up @@ -153,6 +162,9 @@
$N
[1] 10

$n
[1] 5

$estimate
[1] 0.5

Expand All @@ -177,6 +189,9 @@
$N
[1] 32

$n
[1] 32

$estimate
[1] 1

Expand All @@ -201,6 +216,9 @@
$N
[1] 32

$n
[1] 0

$estimate
[1] 0

Expand Down Expand Up @@ -235,6 +253,9 @@
$N
[1] 10

$n
[1] 5

$conf.level
[1] 0.95

Expand Down Expand Up @@ -274,6 +295,9 @@
$N
[1] 32

$n
[1] 32

$conf.level
[1] 0.95

Expand Down Expand Up @@ -313,6 +337,9 @@
$N
[1] 32

$n
[1] 0

$conf.level
[1] 0.95

Expand Down Expand Up @@ -362,6 +389,9 @@
$N
[1] 10

$n
[1] 5

$estimate
[1] 0.5

Expand All @@ -386,6 +416,9 @@
$N
[1] 32

$n
[1] 32

$estimate
[1] 1

Expand All @@ -410,6 +443,9 @@
$N
[1] 32

$n
[1] 0

$estimate
[1] 0

Expand Down Expand Up @@ -444,6 +480,9 @@
$N
[1] 10

$n
[1] 5

$estimate
[1] 0.5

Expand All @@ -468,6 +507,9 @@
$N
[1] 32

$n
[1] 32

$estimate
[1] 1

Expand All @@ -492,6 +534,9 @@
$N
[1] 32

$n
[1] 0

$estimate
[1] 0

Expand Down Expand Up @@ -533,6 +578,9 @@
$N
[1] 80

$n
[1] 50

$estimate
[1] 0.625

Expand All @@ -558,6 +606,9 @@
$N
[1] 80

$n
[1] 50

$estimate
[1] 0.625

Expand All @@ -582,6 +633,9 @@
$N
[1] 80

$n
[1] 50

$estimate
[1] 0.625

Expand All @@ -606,6 +660,9 @@
$N
[1] 80

$n
[1] 50

$estimate
[1] 0.625

Expand Down
Loading