Skip to content

Commit

Permalink
Check ordering in svy CIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Nov 5, 2024
1 parent 901cc30 commit 458cb79
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Suggests:
broom.helpers (>= 1.17.0),
broom.mixed (>= 0.2.9),
car (>= 3.0-11),
cardx (>= 0.2.1),
cardx (>= 0.2.1.9011),
cmprsk,
effectsize (>= 0.6.0),
emmeans (>= 1.7.3),
Expand All @@ -86,6 +86,7 @@ Suggests:
testthat (>= 3.2.0),
withr (>= 2.5.0),
workflows (>= 0.2.4)
Remotes: insightsengineering/cardx
VignetteBuilder:
knitr
RdMacros:
Expand Down
27 changes: 26 additions & 1 deletion tests/testthat/test-add_ci.tbl_svysummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ test_that("add_ci() correctly handles dichotomous variables", {

expect_equal(
tbl$inputs$value |> lapply(as.character),
tbl$cards$add_ci[c("variable", "variable_level")] |> unique() |> deframe()
tbl$cards$add_ci[c("variable", "variable_level")] |> unique() |> deframe() |> lapply(as.character)
)
})

Expand Down Expand Up @@ -771,5 +771,30 @@ test_that("add_ci.tbl_svysummary() ordering for factors", {
dplyr::arrange(label) |>
dplyr::select(label, stat_0, ci_stat_0)
)


# check for issue #2052
data(api, package = "survey")
dclus1 <-
survey::svydesign(
id = ~dnum,
weights = ~pw,
data = apiclus1 |> dplyr::mutate(both2 = factor(both, levels = c("Yes", "No"))),
fpc = ~fpc
)

# checks the order of the CI columns matches the primary column
expect_equal(
dclus1 |>
tbl_svysummary(by = "both", include = stype) |>
add_ci() |>
as.data.frame(col_labels = FALSE) |>
dplyr::pull(ci_stat_1),
dclus1 |>
tbl_svysummary(by = "both2", include = stype) |>
add_ci() |>
as.data.frame(col_labels = FALSE) |>
dplyr::pull(ci_stat_2)
)
})

0 comments on commit 458cb79

Please sign in to comment.