brm_plot_compare {brms.mmrm}R Documentation

Visually compare the marginals of multiple models and/or datasets.

Description

Visually compare the marginals of multiple models and/or datasets.

Usage

brm_plot_compare(
  ...,
  marginal = "response",
  compare = "source",
  axis = "time",
  facet = c("group", "subgroup")
)

Arguments

...

Named tibbles of marginals posterior summaries from brm_marginal_summaries() and/or brm_marginal_data().

marginal

Character of length 1, which kind of marginal to visualize. Must be a value in the marginal column of the supplied tibbles in the ... argument. Only applies to MCMC output, the data is always on the scale of the response variable.

compare

Character of length 1 identifying the variable to display using back-to-back interval plots of different colors. This is the primary comparison of interest. Must be one of "source" (the source of the marginal summaries, e.g. a model or dataset), "time" or "group" (in the non-subgroup case). Can also be "subgroup" if the marginal summaries are subgroup-specific. The value must not be in axis or facet.

axis

Character of length 1 identifying the quantity to put on the horizontal axis. Must be be one of "source" (the source of the marginal summaries, e.g. a model or dataset), "time", or "group" (in the non-subgroup case). If the marginals are subgroup-specific, then axis can also be "subgroup". The value must not be in compare or facet.

facet

Character vector of length 1 or 2 with quantities to generate facets. Each element must be "source" (the source of the marginal summaries, e.g. a model or dataset), "time", "group", or "subgroup", and c(axis, facet) must all have unique elements. "subgroup" is automatically removed if the marginals have no subgroup. If facet has length 1, then faceting is wrapped. If facet has length 2, then faceting is in a grid, and the first element is horizontal facet.

Details

By default, brm_plot_compare() compares multiple models and/or datasets side-by-side. The compare argument selects the primary comparison of interest, and arguments axis and facet control the arrangement of various other components of the plot.

Value

A ggplot object.

See Also

Other visualization: brm_plot_draws()

Examples

if (identical(Sys.getenv("BRM_EXAMPLES", unset = ""), "true")) {
set.seed(0L)
data <- brm_data(
  data = brm_simulate_simple()$data,
  outcome = "response",
  role = "response",
  group = "group",
  time = "time",
  patient = "patient",
  reference_group = "group_1",
  reference_time = "time_1"
)
formula <- brm_formula(
  data = data,
  baseline = FALSE,
  baseline_time = FALSE
)
tmp <- utils::capture.output(
  suppressMessages(
    suppressWarnings(
      model <- brm_model(
        data = data,
        formula = formula,
        chains = 1,
        iter = 100,
        refresh = 0
      )
    )
  )
)
draws <- brm_marginal_draws(model = model, data = data)
suppressWarnings(summaries_draws <- brm_marginal_summaries(draws))
summaries_data <- brm_marginal_data(data)
brm_plot_compare(
  model1 = summaries_draws,
  model2 = summaries_draws,
  data = summaries_data
)
brm_plot_compare(
  model1 = summaries_draws,
  model2 = summaries_draws,
  marginal = "difference"
)
}

[Package brms.mmrm version 0.1.0 Index]