Skip to content

Commit

Permalink
brm_marginal_probabilities()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jun 8, 2023
1 parent cae04bf commit 74c0627
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
22 changes: 11 additions & 11 deletions R/brm_marginal_probabilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
#' all `i` from 1 to `length(direction)`.
#' @examples
#' set.seed(0L)
#' sim <- brm_simulate()
#' data <- sim$data
#' data <- brm_data(
#' data = tibble::as_tibble(brm_simulate()$data),
#' outcome = "response",
#' role = "response",
#' group = "group",
#' time = "time",
#' patient = "patient"
#' )
#' data$group <- paste("treatment", data$group)
#' data$time <- paste("visit", data$time)
#' formula <- brm_formula(
#' response = "response",
#' group = "group",
#' time = "time",
#' patient = "patient",
#' data = data,
#' effect_base = FALSE,
#' interaction_base = FALSE
#' )
Expand All @@ -53,12 +56,9 @@
#' )
#' draws <- brm_marginal_draws(
#' model = model,
#' group = "group",
#' time = "time",
#' patient = "patient",
#' data = data,
#' control = "treatment 1",
#' baseline = "visit 1",
#' outcome = "response"
#' baseline = "visit 1"
#' )
#' brm_marginal_probabilities(draws, direction = "greater", threshold = 0)
brm_marginal_probabilities <- function(
Expand Down
48 changes: 20 additions & 28 deletions tests/testthat/test-brm_marginal_probabilities.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
test_that("brm_marginal_probabilities() on response", {
set.seed(0L)
sim <- brm_simulate(
n_group = 2L,
n_patient = 100L,
n_time = 4L
data <- brm_data(
data = tibble::as_tibble(brm_simulate()$data),
outcome = "response",
role = "response",
group = "group",
time = "time",
patient = "patient"
)
data <- sim$data
data$group <- paste("treatment", data$group)
data$time <- paste("visit", data$time)
formula <- brm_formula(
response = "response",
group = "group",
time = "time",
patient = "patient",
data = data,
effect_base = FALSE,
interaction_base = FALSE
)
Expand All @@ -31,12 +30,9 @@ test_that("brm_marginal_probabilities() on response", {
)
draws <- brm_marginal_draws(
model = model,
group = "group",
time = "time",
patient = "patient",
data = data,
control = "treatment 1",
baseline = "visit 1",
outcome = "response"
baseline = "visit 1"
)
x <- brm_marginal_probabilities(
draws,
Expand Down Expand Up @@ -67,19 +63,18 @@ test_that("brm_marginal_probabilities() on response", {

test_that("brm_marginal_probabilities() on change and multiple probs", {
set.seed(0L)
sim <- brm_simulate(
n_group = 2L,
n_patient = 100L,
n_time = 4L
data <- brm_data(
data = tibble::as_tibble(brm_simulate()$data),
outcome = "response",
role = "change",
group = "group",
time = "time",
patient = "patient"
)
data <- sim$data
data$group <- paste("treatment", data$group)
data$time <- paste("visit", data$time)
formula <- brm_formula(
response = "response",
group = "group",
time = "time",
patient = "patient",
data = data,
effect_base = FALSE,
interaction_base = FALSE
)
Expand All @@ -98,12 +93,9 @@ test_that("brm_marginal_probabilities() on change and multiple probs", {
)
draws <- brm_marginal_draws(
model = model,
group = "group",
time = "time",
patient = "patient",
data = data,
control = "treatment 1",
baseline = "visit 1",
outcome = "change"
baseline = "visit 1"
)
x <- brm_marginal_probabilities(
draws,
Expand Down

0 comments on commit 74c0627

Please sign in to comment.