Bug Report: Mismatched estimates and CIs with add_ci after tbl_svysummary
Closed this issue · 2 comments
louisahsmith commented
When adding confidence intervals to a table created with tbl_svysummary()
that is stratified by a factor variable, the confidence intervals can get attached to the wrong column. This seems to be related to #2036 but is not fixed in version 2.0.3.9003.
data(api, package = "survey")
survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) |>
tbl_svysummary(by = "both", include = c(stype)) |>
add_ci(pattern = "{stat} ({ci})")
apiclus1 <- apiclus1 |> mutate(both2 = factor(both, levels = c("Yes", "No")))
survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) |>
tbl_svysummary(by = "both2", include = c(stype)) |>
add_ci(pattern = "{stat} ({ci})")
ddsjoberg commented
Thank you so much for the report and including a reproducible example, much appreciated. Can you install the dev version of {cardx} and try again? devtools::install_remote("insightsengineering/cardx@restore-types")
. That branch is still a work in progress, but I think it should address this issue.
louisahsmith commented
That seems to have fixed it! Thanks!