Skip to content

Commit

Permalink
fix the issue37
Browse files Browse the repository at this point in the history
  • Loading branch information
kaigu1990 committed May 22, 2024
1 parent f58a695 commit 7f630f7
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@

#' @rdname cdisc_random_data
"rand_adae"

#' Example Datasets with low and high dropout
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' These two datasets are from Mallinckrodt et al.
#' (https://journals.sagepub.com/doi/pdf/10.1177/2168479013501310) which is available
#' via (https://www.lshtm.ac.uk/research/centres-projects-groups/missing-data#dia-missing-data).
#' The original data were from 2 nearly identically designed antidepressant clinical
#' trials that were originally reported by Goldstein et al and Detke et al.
#' Assessments on the Hamilton 17-item rating scale for depression (HAMD17)19 were
#' taken at baseline and weeks 1, 2, 4, 6, and 8 in each trial.
#'
#' @rdname missing_data
"low1"

#' @rdname missing_data
"high1"
3 changes: 3 additions & 0 deletions R/summarize-lsmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ s_get_lsmeans <- function(object,
data.frame(emmeans::test(contr, null = null, delta = 0, side = side, level = conf.level))
)
contr_est_res <- suppressMessages(dplyr::full_join(contr_ci, contr_pval))
if (all(contr_est_res$contrast == paste(paste0(var, rev(ems@levels[[1]])), collapse = " - "))) {
contr_est_res$contrast <- paste(rev(ems@levels[[1]]), collapse = " - ")
}

structure(
list(
Expand Down
Binary file added data-raw/high1.sas7bdat
Binary file not shown.
Binary file added data-raw/low1.sas7bdat
Binary file not shown.
5 changes: 5 additions & 0 deletions data-raw/low_high.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
low1 <- haven::read_sas("./data-raw/low1.sas7bdat")
usethis::use_data(low1, overwrite = TRUE)

high1 <- haven::read_sas("./data-raw/high1.sas7bdat")
usethis::use_data(high1, overwrite = TRUE)
Binary file added data/high1.rda
Binary file not shown.
Binary file added data/low1.rda
Binary file not shown.
29 changes: 29 additions & 0 deletions man/missing_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test-summarize-lsmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@ test_that("s_get_lsmeans works as expected for ancova", {
tolerance = 0.0001
)
})

test_that("s_get_lsmeans works as expected when the grouping variable is numeric", {
data("low1")
fit <- low1 %>%
dplyr::filter(week == 8 & !is.na(change)) %>%
lm(formula = change ~ basval + trt)
res <- s_get_lsmeans(fit, "trt")

expect_identical(dim(res$lsm_est), c(2L, 8L))
expect_identical(dim(res$lsm_contr), c(1L, 8L))
expect_identical(res$lsm_contr$contrast, "2 - 1")
})

0 comments on commit 7f630f7

Please sign in to comment.