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 and analytical approaches, support for multiple decision rules (direction, threshold, rope), sequential and two-stage designs, and visualisation helpers for power curves, precision, Bayes factors, and robustness.

Installation

You can install the development version from GitHub:

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

Example

Here is a minimal example to get started. For speed in a README, the code is not evaluated on knit.

library(powerbrmsINLA)

# Run Bayesian power analysis
results <- brms_inla_power(
  formula = outcome ~ treatment,
  effect_name = "treatment", 
  effect_grid = c(0.2, 0.5, 0.8),
  sample_sizes = c(50, 100),
  nsims = 5  # Reduced for speed
)

# Inspect summary results
results$summary

# Plot power heatmap  
plot_power_heatmap(results)

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

The package handles the vast majority of Bayesian power analysis scenarios. For computationally demanding models, standard Bayesian modeling best practices apply (adequate sample sizes, model complexity appropriate to data).

Package documentation

If you use pkgdown you can build a website:

usethis::use_pkgdown()           # once, to set up pkgdown
pkgdown::build_site()            # build the site locally
# usethis::use_pkgdown_github_pages()  # set up GitHub Pages

License

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

Copy Link

Version

Install

install.packages('powerbrmsINLA')

Monthly Downloads

140

Version

1.1.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Tony Myers

Last Published

November 16th, 2025

Functions in powerbrmsINLA (1.1.1)

.auto_data_generator

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

Create a ggplot2 Line Layer with Version-Compatible Width
.brms_to_inla_formula2

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

Scale Fill for Viridis Continuous Data
min_n_beta_binom

Minimum n for Target Assurance (Beta-Binomial)
plot_precision_assurance_curve

Plot Precision Assurance Curve (Multi-Effect Grid Friendly)
plot_assurance_with_robustness

Plot Assurance with Robustness Ribbon (Multi-Effect Grid Friendly)
.scale_fill_viridis_discrete

Scale Fill for Viridis Discrete Data
.map_brms_priors_to_inla

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

Parse brms-like Random Effects Terms (Modern Robust)
plot_bf_assurance_curve

Bayes-factor assurance curve (user-facing wrapper)
plot_precision_fan_chart

Precision assurance as a function of sample size
plot_decision_assurance_curve

Plot Decision Assurance Curve (Multi-Effect Grid Friendly)
plot_bf_heatmap

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

Bayes-factor assurance curve with Wilson CIs (multi-effect grid friendly)
plot_bf_expected_evidence

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

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

Plot Bayesian Power / Assurance Heatmap (Multi-Effect Grid Friendly)
plot_power_contour

Draw a filled contour plot of assurance for a chosen metric, as a function of two effect grid columns and sample size.
or_or

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

Highest Density Interval from an Inverse CDF
.to_inla_family

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

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

Plot Interaction Assurance Surface/Heatmap/Lines (Multi-Effect Grid Friendly)
decide_sample_size

Decide recommended sample size from power/assurance results
beta_weights_on_grid

Beta-Prior Weights Over an Effect Grid
.add_contour_lines

Add Contour Lines to a ggplot2 Plot
brms_inla_power

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

Add sample-size decision overlay to an assurance contour
.plot_decision_assurance_curve_from_summary

Plot decision/assurance curve across n
.compute_assurance

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

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

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

Design-based wrapper for Bayesian power / assurance
beta_binom_power

Analytic Assurance for Beta-Binomial Designs
.geom_point_lw

Create a ggplot2 Point Layer with Version-Compatible Width
brms_inla_power_two_stage

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

Compute Mean Assurance for a Given Metric (Modern, Multi-Effect Compatible)