diff --git a/R/brm_data.R b/R/brm_data.R index acf195f1..b091df9b 100644 --- a/R/brm_data.R +++ b/R/brm_data.R @@ -20,6 +20,8 @@ #' @param base Character of length 1, name of the baseline response variable. #' Supply `NULL` to ignore or omit. #' @param time Character of length 1, name of the discrete time variable. +#' Must be a character or factor variable in the data, and the levels +#' must be alphanumeric. #' @param patient Character of length 1, name of the patient ID variable. #' @param covariates Character vector of names of other covariates. #' @examples diff --git a/R/brm_marginal_draws.R b/R/brm_marginal_draws.R index e012253c..ff14a9e0 100644 --- a/R/brm_marginal_draws.R +++ b/R/brm_marginal_draws.R @@ -151,12 +151,20 @@ brm_marginal_draws <- function( control = control ) } + draws_sigma <- get_draws_sigma(model = model, time = time) + draws_effect <- get_draws_effect( + draws_difference = draws_difference, + draws_sigma = draws_sigma, + groups = groups, + times = times + ) out <- list() out$response <- draws_response if (identical(role, "response")) { out$change <- draws_change } out$difference <- draws_difference + out$effect <- draws_effect out } @@ -184,6 +192,24 @@ subtract_control <- function(draws, groups, times, control) { out } +get_draws_sigma <- function(model, time) { + draws <- tibble::as_tibble(posterior::as_draws_df(model)) + draws <- draws[, grep("^b_sigma_", colnames(draws), value = TRUE)] + colnames(draws) <- gsub("^b_sigma_", "", colnames(draws)) + colnames(draws) <- gsub(paste0("^", time), "", x = colnames(draws)) + exp(draws) +} + +get_draws_effect <- function(draws_difference, draws_sigma, groups, times) { + out <- draws_difference + for (group in groups) { + for (time in times) { + browser() + } + } + out +} + name_marginal <- function(group, time) { sprintf("%s%s%s", group, brm_sep(), time) } diff --git a/R/brm_package.R b/R/brm_package.R index 332753c5..00c6688a 100644 --- a/R/brm_package.R +++ b/R/brm_package.R @@ -32,7 +32,7 @@ #' @importFrom purrr map_dbl map_df map2_df #' @importFrom rlang warn #' @importFrom stats as.formula median model.matrix rnorm runif sd -#' @importFrom tibble tibble +#' @importFrom tibble as_tibble tibble #' @importFrom tidyr expand_grid pivot_longer pivot_wider #' @importFrom tidyselect any_of everything #' @importFrom trialr rlkjcorr