Learn R Programming

powerbrmsINLA

Overview

powerbrmsINLA provides tools for Bayesian power analysis and assurance calculations using the statistical frameworks of brms and INLA.

It includes simulation-based approaches, support for multiple decision rules (direction, threshold, ROPE, Bayes factors, precision), sequential and two-stage adaptive designs, and a comprehensive suite of visualisation functions.

What's New in 1.3.0

  • Sequential Bayesian analysis module: sequential_design() for prespecifying a sequential analysis (with an MD5 fingerprint of all decision-relevant fields for preregistration), sequential_analysis() for interim monitoring of real accumulating data with an auditable decision trail, plot_sequential_monitor() for trajectory plots, and brms_inla_sequential_trial() for simulating a sequential design's operating characteristics (stopping probabilities, expected sample size, early-stop exaggeration).
  • Validation hardening: brms_inla_power() now raises an error when effect_name does not match a formula-level fixed-effect term and the built-in data generator is in use (previously such a name was silently ignored).
  • decide_sample_size() in conditional mode now requires at least one decision target, and no longer mistakes the per-cell SD-moment summary columns for effect-grid columns.
  • Breaking change: in brms_inla_power_sequential() summaries, the column previously named assurance is now conditional_power (the old name was statistically misleading).
  • Bug fix: brms_inla_power_two_stage() no longer errors when called with default error_sd / obs_per_group.
  • All engines now fail early with an informative message when INLA is absent.

What's New in 1.2.0

  • Unconditional Bayesian assurance via compute_assurance() — averages conditional power over a design prior on the effect size (O'Hagan & Stevens, 2001).
  • assurance_prior_weights() for constructing normalised design-prior weights (normal, uniform, beta) over an effect grid.
  • decide_sample_size() with both assurance mode (design prior) and conditional mode for recommending sample sizes from simulation output.
  • validate_inla_vs_brms() for spot-checking INLA posterior estimates against brms/Stan.
  • brms-to-INLA prior translation with full audit trail — specify analysis priors using brms::prior() syntax.
  • Variance uncertainty integrationerror_sd and group_sd now accept distributional specifications (halfnormal, lognormal, uniform) so that power is integrated over variance uncertainty.
  • Marginal-likelihood Bayes factors (bf_method = "marglik") alongside the existing Savage-Dickey method.
  • Automatic INLA thread detection when inla_num_threads = NULL.
  • 15 new plotting functions for assurance, Bayes factor, decision-rule, precision, and multi-effect visualisation.
  • Print methods for brms_inla_power, powerbrmsINLA_assurance, and powerbrmsINLA_sample_size objects.

See NEWS.md for the full changelog.

Installation

Install from CRAN:

install.packages("powerbrmsINLA")

INLA is listed under Suggests and must be installed separately:

if (!requireNamespace("INLA", quietly = TRUE)) {
  install.packages(
    "INLA",
    repos = c(getOption("repos"),
              INLA = "https://inla.r-inla-download.org/R/stable"),
    dep = TRUE
  )
}

To install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("Tony-Myers/powerbrmsINLA")

Quick Example

library(powerbrmsINLA)

# Step 1: Conditional power simulation
results <- brms_inla_power(
  formula      = y ~ treatment,
  effect_name  = "treatment",
  effect_grid  = c(0.2, 0.5, 0.8),
  sample_sizes = c(50, 100),
  nsims        = 50,
  seed         = 123
)
results$summary

# Step 2: Unconditional assurance (new in 1.2.0)
assurance <- compute_assurance(
  results,
  prior_weights = list(dist = "normal", mean = 0.5, sd = 0.2),
  metric = "direction"
)
print(assurance)

# Step 3: Sample size recommendation
decide_sample_size(
  results,
  direction = 0.80,
  prior_weights = list(dist = "normal", mean = 0.5, sd = 0.2)
)

Model Complexity Considerations

For optimal performance:

  • Simple to moderate models: All sample sizes supported.
  • Complex random effects (e.g., (1 + time | subject)): Recommend n >= 50 subjects.
  • Large effect grids: Consider starting with fewer simulations (nsims = 50-100) for initial exploration, or use the sequential/two-stage engines.

Citation

If you use powerbrmsINLA in published work, please cite:

Myers, T. (2026). powerbrmsINLA: Bayesian Power Analysis Using 'brms' and 'INLA'. R package version 1.2.0. https://cran.r-project.org/package=powerbrmsINLA

License

This package is released under the MIT License. See the LICENSE file for details.

Copy Link

Version

Install

install.packages('powerbrmsINLA')

Monthly Downloads

443

Version

1.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Tony Myers

Last Published

July 2nd, 2026

Functions in powerbrmsINLA (1.3.0)

.geom_line_lw

Create a ggplot2 Line Layer with Version-Compatible Width Creates a geom_line with a width argument adapted to ggplot2 version.
decide_sample_size

Decide recommended sample size from power/assurance results
compute_assurance

Compute unconditional Bayesian assurance from simulation results
.geom_point_lw

Create a ggplot2 Point Layer with Version-Compatible Width Creates a geom_point with a width argument adapted to ggplot2 version.
.add_contour_lines

Add Contour Lines to a ggplot2 Plot Wrapper around geom_contour with preset defaults for colour, alpha, width. Uses the correct linewidth/size argument depending on ggplot2 version.
.compute_weights_from_dist

Compute weights from a parametric prior distribution over an effect grid
.brms_to_inla_formula2

Convert brms Formula to INLA Formula (Multi-Fixed Support)
.auto_data_generator

Automatic Data Generator for brms + INLA Simulation (Multi-Effect Ready)
.compute_assurance

Compute Mean Assurance for a Given Metric (Multi-Effect Compatible) Summarises simulation results and computes proportion passing for decision rule metric.
.eval_prior_density

Evaluate a prior density over a continuous x grid
.map_brms_priors_to_inla

Map brms Priors to INLA Priors (Multi-Fixed)
.sample_sd_spec

Draw One Sample from an SD Specification
.sample_design_prior

Sample a true effect from a design-prior specification
.parse_re_terms

Parse brms-like Random Effects Terms (Modern Robust)
.seq_design_fingerprint

MD5 fingerprint of a sequential design's decision-relevant fields
.scale_fill_viridis_continuous

Scale Fill for Viridis Continuous Data
.plot_decision_assurance_curve_from_summary

Plot decision/assurance curve across n
.gg_line_arg

Determine ggplot2 Line Width Argument Name by Version Returns the correct argument name for line width in ggplot2, depending on package version ("linewidth" for >= 3.4.0, else "size").
.should_stop_binom

Wilson Confidence Interval Early Stopping Rule Determines whether to stop early based on Wilson binomial confidence interval.
.scale_fill_viridis_discrete

Scale Fill for Viridis Discrete Data
.to_inla_family

Map a brms Family to an INLA Family (Modern, Robust)
min_n_beta_binom

Minimum n for Target Assurance (Beta-Binomial)
plot_assurance_with_robustness

Plot Conditional Power with Robustness Ribbon (Multi-Effect Grid Friendly)
plot_bf_expected_evidence

Plot Expected Evidence (mean log10 BF10, Multi-Effect Grid Friendly)
plot_bf_assurance_curve

Bayes-factor conditional power curve (user-facing wrapper)
hdi_of_icdf

Highest Density Interval from an Inverse CDF
plot_bf_heatmap

Plot Bayes Factor Heatmap (mean log10 BF10, Multi-Effect Grid Friendly)
or_or

Internal Coalesce Operator Returns the left-hand side if it is not NULL, otherwise the right-hand side.
plot_bf_assurance_curve_smooth

Conditional Bayesian power curve for the Bayes factor criterion with Wilson CIs (multi-effect grid friendly)
plot_sequential_monitor

Plot a sequential analysis trajectory with stopping boundaries
plot_decision_threshold_contour

Plot Decision Threshold Contour (Multi-Effect Grid Friendly)
plot_precision_fan_chart

Precision conditional power as a function of sample size
plot_assurance_curve

Plot Assurance Curve(s) vs Sample Size
plot_power_heatmap

Plot Conditional Bayesian Power Heatmap (Multi-Effect Grid Friendly)
plot_decision_assurance_curve

Plot Conditional Power Curve for a Decision Rule (Multi-Effect Grid Friendly)
plot_power_contour

Draw a filled contour plot of conditional Bayesian power for a chosen metric, as a function of two effect grid columns and sample size.
plot_design_prior

Plot Design Prior Density over the Effect Grid
plot_interaction_surface

Plot Interaction Conditional Power Surface/Heatmap/Lines (Multi-Effect Grid Friendly)
plot_power_assurance_overlay

Plot Conditional Power Curves with Assurance Overlay
plot_precision_assurance_curve

Plot Precision Conditional Power Curve (Multi-Effect Grid Friendly)
print.powerbrmsINLA_sample_size

Print method for powerbrmsINLA_sample_size objects
validate_inla_vs_brms

Spot-check INLA posterior estimates against brms/Stan
validate_sd_spec

Validate an SD Specification for error_sd or group_sd
print.powerbrmsINLA_assurance

Print method for powerbrmsINLA_assurance objects
print.powerbrmsINLA_seq_trial

Print method for sequential trial simulation results
sequential_analysis

Analyse accumulated real data at a sequential interim look
print.powerbrmsINLA_seq_design

Print method for sequential design objects
sequential_design

Prespecify a sequential Bayesian analysis design
print.brms_inla_power

Print method for brms_inla_power result objects
print.powerbrmsINLA_seq_monitor

Print method for sequential analysis monitor objects
beta_binom_power

Analytic Assurance for Beta-Binomial Designs
brms_inla_power_two_stage

Two-Stage Bayesian Assurance Simulation (Multi-Effect, User-Friendly API)
add_decision_overlay

Add sample-size decision overlay to a conditional power contour
beta_weights_on_grid

Beta-Prior Weights Over an Effect Grid
brms_inla_power_sequential

Sequential Bayesian Assurance Simulation Engine (Modern, Multi-Effect Ready)
assurance_prior_weights

Create prior weights over an effect grid for use with compute_assurance()
brms_inla_power_parallel

Parallel wrapper for fixed-design Bayesian power / assurance simulations
brms_inla_sequential_trial

Simulate a sequential Bayesian trial with interim stopping rules
brms_inla_power

Core Bayesian Assurance / Power Simulation (Modern, Multi-Effect Ready)
brms_inla_power_design

Design-based wrapper for Bayesian power / assurance