inst/specification.md

title: "Interface package specification" author: "Will Landau, Kevin Kunzmann, Yoni Sidi, Christian Stock" format: html: toc: true toc-depth: 3 number-sections: true

```{r, include = FALSE} knitr::opts_chunk$set(eval = FALSE)


# Introduction

This document is the draft specification for `brms.mmrm`.

# Data functions

## `brm_data_preprocess()`

This function will be a general-purpose pipe-friendly data preprocessing function which accepts a simple tibble and returns a simple tibble. It will call a sequence of more specific pipe-friendly functions exposed to the user for individual tasks including but not limited to dropping patients with no observed post-baseline response, inserting explicit rows for implicitly missing responses, and sorting rows by patient and timepoint. 

### Signature

```{r}
brm_data_preprocess(
  data,
  response = "CHG",
  group = "TRT01P",
  patient = "USUBJID",
  rep = "AVISITN",
  baseline = "BASE",
  covariates = character(0)
)

Value

A preprocessed tibble with the data to analyze.

Arguments

Recipe methods

It is possible to implement methods in this package which extend the existing recipes package to make data processing easier and more conveneint for MMRMs for users already familiar with recipes. https://github.com/tidymodels/themis is an example of such an implementation for a different scenario.

brm_data_validate()

Run assertions on the dataset to verify it is clean enough to analyze with the MMRM. This function will be exposed to the user and can be run after a successful call to brm_data_preprocess(). In addition, the function that runs the MMRM will run it internally to check the data. Possible assertions may include:

Signature

brm_data_validate(
  data,
  response = "CHG",
  group = "TRT01P",
  patient = "USUBJID",
  rep = "AVISITN",
  baseline = "BASE",
  covariates = character(0)
)

Arguments

Same as brm_data_preprocess().

Value

If there are no problems with the data, this function should invisibly return NULL. If problems are detected, the function should return an informative classed error, i.e. rlang::abort(message = "something informative", class = "<PACKAGE_NAME>_error").

brm_simulate()

Simulate a dataset from the prior predictive distribution of a basic MMRM with random effects marginalized out. Use brms to do this. This function corresponds to the brm_model() discussed later.

Signature

brm_model(
  data,
  formula = ~ ...,
  priors = ...,
  n_groups = 2,
  n_patients = 100,
  n_times = 4,
  n_binary = 0,
  n_continuous = 0,
  dropout = 0.1,
  ...
)

Value

A list with 2 elements:

Arguments

Model functions

Each kind of model will have its own user-side exported function. We will start with a basic MMRM with random effects marginalized out.

brm_model()

Fit a basic MMRM with random effects marginalized out.

Priors

It is an open question how we specify priors for brms. It would be nice to use something simpler and more situation-specific than brms::prior(...) + brms::prior(...) + ....

Signature

brm_model(
  data,
  formula = ~ ...,
  priors = ...,
  n_chains = 4,
  n_workers = 1,
  n_warmup = 2e3,
  n_iterations = 4e3,
  ...
)

Value

A classed object (S7?) with the brms fitted model object.

Arguments

Results

brm_summary()

S7-compatible method to conduct inference on the marginal posterior using emmeans.

Signature

We consider two S7-compatible methods: one for models fit with the package, and another for MMRMs fit directly by interfacting with brms.

brm_summary.brm_model(
  object,
  data,
  response_is_change = TRUE,
  group_reference = "Placebo",
  interval_level = 0.95,
  effect_threshold = 0,
  effect_comparison = ">",
  ...
)
brm_summary.brms(
  object,
  data,
  response_is_change = TRUE,
  group_reference = "Placebo",
  interval_level = 0.95,
  effect_threshold = 0,
  effect_comparison = ">",
  ...
)

Value

A data frame with one row per combination of treatment group and discrete time point (rep). Columns may include:

Arguments

brm_plot() and plot()

S7-compatible method to plot intervals of the fitted model marginal posterior against intervals on the data. For now this section shows only one possible plot we could choose for the plot() method, but there are others we could consider, e.g. posterior density plots from ggdist.

Signature

brm_plot(model, data)
plot.brm_model(x, y = NULL, data, ...) # model fit with the package
plot.brms(x, y = NULL, data, ...) # mmrm fit directly with brms

Value

A ggplot2 object plotting the fitted model marginal posterior (estimated marginal means and posterior intervals of the response) against the data (point estimates and confidence intervals).

Arguments

brm_convergence()

Show concise summaries of basic convergence diagnostics for a fitted brms model. The documentation of the function should include background information on the convergence diagnostics to help users determine whether the MCMC succeeded, along with recommendations to address any specific issues with convergence that the diagnostics discover.

Signature

brm_convergence.brm_model(model) # model fit with the package
brm_convergence.brms(model) # mmrm fit directly with brms

Value

A one-row data frame with columns for maximum Rhat, minimum bulk ESS, minimum tail ESS, and number of divergent transitions.

Arguments

Additional functionality

Questions



Try the brms.mmrm package in your browser

Any scripts or data that you put into this service are public.

brms.mmrm documentation built on Oct. 3, 2024, 1:08 a.m.