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

Update DESCRIPTION #1321

Merged
merged 2 commits into from
Oct 8, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Imports:
rlang (>= 1.1.0),
scales (>= 1.2.0),
stats,
survival (>= 3.7-0),
survival (>= 3.6-4),
tibble (>= 2.0.0),
tidyr (>= 0.8.3),
utils
Expand Down
90 changes: 59 additions & 31 deletions tests/testthat/test-odds_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ testthat::test_that("or_clogit estimates right OR and CI", {
stringsAsFactors = TRUE
)

result <- or_clogit(data, conf_level = 0.95)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- or_clogit(data, conf_level = 0.95)
)

# from SAS
res <- testthat::expect_silent(result)
Expand Down Expand Up @@ -62,13 +66,17 @@ testthat::test_that("s_odds_ratio estimates right OR and CI (stratified analysis
strata = factor(sample(c("C", "D"), 100, TRUE))
)

result <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata")
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata")
)
)

res <- testthat::expect_silent(result)
Expand All @@ -86,15 +94,19 @@ testthat::test_that("s_odds_ratio returns error for incorrect groups", {
"Arms A+B" = c("A", "B")
)

testthat::expect_error(result <- s_odds_ratio(
df = subset(data, grp == "A"),
.var = "rsp",
.ref_group = subset(data, grp == "B"),
.in_ref_col = FALSE,
.df_row = data,
variables = list(arm = "grp", strata = "strata"),
groups_list = groups
))
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- testthat::expect_error(s_odds_ratio(
df = subset(data, grp == "A"),
.var = "rsp",
.ref_group = subset(data, grp == "B"),
.in_ref_col = FALSE,
.df_row = data,
variables = list(arm = "grp", strata = "strata"),
groups_list = groups
))
)
})

testthat::test_that("estimate_odds_ratio estimates right OR and CI (unstratified analysis)", {
Expand All @@ -120,10 +132,14 @@ testthat::test_that("estimate_odds_ratio estimates right OR and CI (stratified a
strata = factor(sample(c("C", "D"), 100, TRUE))
)

result <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "A", split_fun = ref_group_position("first")) %>%
estimate_odds_ratio(vars = "rsp", variables = list(arm = "grp", strata = "strata")) %>%
build_table(df = data)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "A", split_fun = ref_group_position("first")) %>%
estimate_odds_ratio(vars = "rsp", variables = list(arm = "grp", strata = "strata")) %>%
build_table(df = data)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
Expand Down Expand Up @@ -154,7 +170,11 @@ testthat::test_that("estimate_odds_ratio works with strata and combined groups",
groups_list = groups
)

result <- build_table(lyt = lyt, df = anl)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- build_table(lyt = lyt, df = anl)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
Expand All @@ -172,14 +192,18 @@ testthat::test_that("s_odds_ratio method argument works", {
stringsAsFactors = TRUE
)

res <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata"),
method = "approximate"
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
res <- s_odds_ratio(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
.df_row = dta,
variables = list(arm = "grp", strata = "strata"),
method = "approximate"
)
)

testthat::expect_false(all(is.na(res$or_ci)))
Expand Down Expand Up @@ -213,7 +237,11 @@ testthat::test_that("estimate_odds_ratio method argument works", {
split_cols_by(var = "grp", ref_group = "B") %>%
estimate_odds_ratio(vars = "rsp", variables = list(arm = "grp", strata = "strata"), method = "approximate")

result <- build_table(lyt, df = dta)
# https://github.com/therneau/survival/issues/240
withr::with_options(
opts_partial_match_old,
result <- build_table(lyt, df = dta)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
Expand Down
Loading