Skip to content

Commit

Permalink
begin to sketch #29
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jul 25, 2023
1 parent a077dd0 commit 7bc08bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions R/brm_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions R/brm_marginal_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion R/brm_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7bc08bf

Please sign in to comment.