Skip to content

Commit

Permalink
add ard_categorical_ci.data.frame tests. (#228)
Browse files Browse the repository at this point in the history
adding categorical_ci_data.frame tests (to match
continuous_ci_data.frame)

closes [sme-task]
insightsengineering/sme-tasks#704



--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [ ] If a bug was fixed, a unit test was added.
- [ ] If a new `ard_*()` function was added, it passes the ARD
structural checks from `cards::check_ard_structure()`.
- [ ] If a new `ard_*()` function was added, `set_cli_abort_call()` has
been set.
- [ ] If a new `ard_*()` function was added and it depends on another
package (such as, `broom`), `is_pkg_installed("broom")` has been set in
the function call and the following added to the roxygen comments:
`@examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg =
"broom""))`
- [ ] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cardx (development version)`". If there is an issue
associated with the pull request, reference it in parentheses at the end
update (see `NEWS.md` for examples).
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
  • Loading branch information
ayogasekaram authored Nov 1, 2024
1 parent 9c0f38c commit 9b21d61
Showing 1 changed file with 151 additions and 0 deletions.
151 changes: 151 additions & 0 deletions tests/testthat/test-ard_categorical_ci.data.frame.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
test_that("ard_categorical_ci.data.frame(method = 'wald')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "wald"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_wald(mtcars[["vs"]]) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'waldcc')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "waldcc"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_wald(mtcars[["vs"]], correct = TRUE) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'clopper-pearson')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "clopper-pearson"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_clopper_pearson(mtcars[["vs"]]) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'wilson')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "wilson"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_wilson(mtcars[["vs"]]) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'wilsoncc')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "wilsoncc"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_wilson(mtcars[["vs"]], correct = TRUE) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'strat_wilson')", {
skip_if_not(is_pkg_installed("broom"))

mtcars$gear <- as.factor(mtcars$gear)
expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
strata = "gear",
method = "strat_wilson"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_strat_wilson(mtcars[["vs"]], strata = as.factor(mtcars[["gear"]])) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'strat_wilsoncc')", {
skip_if_not(is_pkg_installed("broom"))

mtcars$gear <- as.factor(mtcars$gear)
expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
strata = "gear",
method = "strat_wilsoncc"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_strat_wilson(mtcars[["vs"]], strata = as.factor(mtcars[["gear"]]), correct = TRUE) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'jeffreys')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "jeffreys"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_jeffreys(mtcars[["vs"]]) |>
unlist() |> unname()
)
})

test_that("ard_categorical_ci.data.frame(method = 'agresti-coull')", {
skip_if_not(is_pkg_installed("broom"))

expect_equal(
ard_categorical_ci(
mtcars,
variables = vs,
method = "agresti-coull"
) |>
dplyr::select(stat) |> unlist() |> unname(),
proportion_ci_agresti_coull(mtcars[["vs"]]) |>
unlist() |> unname()
)
})

test_that("ard_continuous_ci.data.frame() follows ard structure", {
skip_if_not(is_pkg_installed("broom"))

expect_silent(
ard_categorical_ci(
mtcars,
variables = vs,
method = "wald"
) |>
cards::check_ard_structure()
)
})

0 comments on commit 9b21d61

Please sign in to comment.