Agent skill

R Bayes

by ab604 in ab604/claude-code-r-skills

Patterns for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects.

MITAuto-check passed

Install R Bayes

skills CLI
$ npx skills add ab604/claude-code-r-skills --skill r-bayes -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ab604/claude-code-r-skills r-bayes --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ab604/claude-code-r-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/r-bayes .claude/skills/r-bayes && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
r-bayes
GitHub stars
207
Used in
2 other repos
Token cost
~2.5k tokens
SKILL.md length
185 words
Files
1
Skills in repo
8
Repo updated
First seen
Licence
MIT

At a glance

Patterns for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects.

  • Works in 9 steps: Define causal DAG with dagitty → Validate DAG against data with… → Identify adjustment sets for target… → …
  • Performing Bayesian analysis
  • SKILL.md covers Core Packages, Directed Acyclic Graphs (DAGs), Bayesian Regression with brms and Multilevel Models, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

R Bayes is an agent skill from ab604/claude-code-r-skills. Patterns for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects. Use when performing Bayesian analysis.

Its SKILL.md is about 2.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The repository describes itself as: Claude Code configurations for R development. The licence is MIT.

When your agent uses it

  • Performing Bayesian analysis

Example prompts

  • “Use the r-bayes skill to pattern for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects”
  • “/r-bayes”

Workflow steps

9 steps, taken from the first numbered list in SKILL.md.

  1. Define causal DAG with dagitty
  2. Validate DAG against data with localTests()
  3. Identify adjustment sets for target effects
  4. Specify priors based on domain knowledge
  5. Fit brms model with random effects for nested data
  6. Check diagnostics (convergence, PPCs)
  7. Extract posteriors for inference
  8. Compute marginal effects on interpretable scale
  9. Visualize effects with uncertainty

What it can do on your machine

Read from SKILL.md and the folder at commit 529de4f. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are r).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

R Bayes loads about 2.5k tokens when it runs. Until then it costs about 41 tokens; SKILL.md has 185 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~41
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ab604/claude-code-r-skills at commit 529de4f, republished under its MIT licence (© ab604). 185 words, ~2,467 tokens.

Download SKILL.mdSave it as .claude/skills/r-bayes/SKILL.md (or your agent's skills folder).
name
r-bayes
description
Patterns for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects. Use when performing Bayesian analysis.

Core Packages

r
library(brms)
library(cmdstanr)
library(dagitty)
library(ggdag)
library(marginaleffects)
library(tidybayes)
library(bayesplot)

Directed Acyclic Graphs (DAGs)

Prior to causal inference, create and validate DAGs with dagitty and ggdag.

Define DAG Structure
r
dag <- dagitty('
dag {
  # Node positions for visualization
  exposure [pos="0,1"]
  mediator [pos="1,1"]
  outcome [pos="2,1"]
  confounder [pos="1,0"]

  # Edges (arrows)
  confounder -> exposure
  confounder -> outcome
  exposure -> mediator
  mediator -> outcome
  exposure -> outcome
}
')
Identify Adjustment Sets
r
# For direct effect
adjustmentSets(dag, exposure = "treatment", outcome = "outcome", effect = "direct")

# For total effect
adjustmentSets(dag, exposure = "treatment", outcome = "outcome", effect = "total")
Validate DAG Against Data
r
# Get implied conditional independencies
implied_cis <- impliedConditionalIndependencies(dag)

# Test against data
ci_results <- localTests(dag, data = analysis_data, type = "cis")

# Assess validation
ci_df <- as.data.frame(ci_results)
ci_df$independent <- ci_df$p.value > 0.05
pct_supported <- 100 * mean(ci_df$independent, na.rm = TRUE)

cat(sprintf("DAG support: %.1f%% of implied CIs hold\n", pct_supported))
Visualize DAG
r
dag_tidy <- tidy_dagitty(dag)

ggplot(dag_tidy, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_dag_edges(edge_colour = "grey50") +
  geom_dag_point(size = 20) +
  geom_dag_text(size = 3.5, color = "black") +
  theme_dag() +
  labs(title = "Causal DAG")

Bayesian Regression with brms

Standard Configuration
r
options(mc.cores = 4)

# Standard brms model call
model <- brm(
  formula = outcome ~ predictor1 + predictor2 + (1 | group_id),
  data = model_data,
  family = bernoulli(link = "logit"),  # For binary outcomes
  prior = priors,
  sample_prior = "yes",  # For prior-posterior comparison
  chains = 4,
  cores = 4,
  iter = 4000,
  warmup = 1000,
  control = list(
    adapt_delta = 0.95,
    max_treedepth = 15
  ),
  seed = 123,  # Set seed for reproducibility
  backend = "cmdstanr",
  file = "models/model_name",         # Cache compiled model
  file_refit = "on_change"            # Only refit if formula/data change
)
Priors

Store priors separately and define explicitly:

r
priors <- c(
  prior(normal(0, 2), class = "Intercept"),
  prior(normal(0, 1), class = "b"),                    # Fixed effects
  prior(exponential(1), class = "sd"),                 # Random effect SD
  prior(lkj(2), class = "cor")                         # Correlation priors
)

# Get default priors for a formula
get_prior(outcome ~ predictor + (1 | id), data = data, family = bernoulli())
Common Families
r
# Binary outcome
family = bernoulli(link = "logit")

# Count data
family = poisson(link = "log")
family = negbinomial(link = "log")

# Continuous
family = gaussian()
family = student()  # Robust to outliers

# Ordinal
family = cumulative(link = "logit")

Multilevel Models

Random Intercepts
r
# Random intercept per participant
outcome ~ predictors + (1 | participant_id)
Random Slopes
r
# Random intercept and slope for time
outcome ~ time + predictors + (1 + time | participant_id)
Crossed Random Effects
r
# Participants nested in groups, items crossed
response ~ predictors + (1 | participant_id) + (1 | item_id)

Within-Person Centering

For longitudinal data, separate between-person and within-person effects:

r
# Create person-centered variables
model_data <- data |>
  group_by(participant_id) |>
  mutate(
    # Between-person means (stable trait)
    predictor_mean = mean(predictor, na.rm = TRUE),

    # Within-person deviations (dynamic change)
    predictor_dev = predictor - predictor_mean,

    # Volatility (person-level SD)
    predictor_sd = sd(predictor, na.rm = TRUE)
  ) |>
  ungroup() |>
  # Standardize
  mutate(
    predictor_mean_z = scale(predictor_mean)[, 1],
    predictor_dev_z = scale(predictor_dev)[, 1]
  )

# Model with both components
model <- brm(
  outcome ~ predictor_mean_z + predictor_dev_z + (1 | participant_id),
  data = model_data,
  family = bernoulli()
)
Lagged Predictors for Temporal Precedence
r
# Create lagged predictors within person
model_data <- data |>
  group_by(participant_id) |>
  arrange(time) |>
  mutate(
    # Lagged values (from previous timepoint)
    predictor_lag = lag(predictor, order_by = time),
    predictor_dev_lag = lag(predictor_dev, order_by = time)
  ) |>
  ungroup()

# Test if t-1 predicts outcome at t (establishes temporal precedence)
model_lagged <- brm(
  outcome ~ predictor_dev_lag_z + predictor_mean_z + (1 | participant_id),
  ...
)

Extracting and Interpreting Results

Extract Posterior Samples
r
posterior <- as_draws_df(model)

# Access specific parameter
samples <- posterior$b_predictor_z

# Summary statistics
tibble(
  estimate = median(samples),
  lower_95 = quantile(samples, 0.025),
  upper_95 = quantile(samples, 0.975),
  lower_80 = quantile(samples, 0.10),
  upper_80 = quantile(samples, 0.90),
  prob_negative = mean(samples < 0),
  prob_positive = mean(samples > 0)
)
Odds Ratios (for logistic models)
r
# Convert log-odds to odds ratios
effects_df <- effects_df |>
  mutate(
    OR = exp(estimate),
    OR_lower = exp(lower_95),
    OR_upper = exp(upper_95)
  )
Posterior Probability of Direction
r
# P(effect is protective)
prob_protective <- mean(posterior$b_predictor < 0)

# P(effect is harmful)
prob_harmful <- mean(posterior$b_predictor > 0)

# P(|effect| > some threshold)
prob_meaningful <- mean(abs(posterior$b_predictor) > 0.1)
Compare Effect Magnitudes
r
# Test if within-person effect is larger than between-person
diff <- abs(posterior$b_predictor_dev_z) - abs(posterior$b_predictor_mean_z)
prob_within_larger <- mean(diff > 0)

cat(sprintf("P(|within| > |between|) = %.1f%%\n", 100 * prob_within_larger))

Marginal Effects with marginaleffects

Average Marginal Effects (AME)
r
# Change in P(outcome) per 1 unit change in predictor
ame <- avg_slopes(
  model,
  variables = c("predictor1_z", "predictor2_z"),
  type = "response"  # Probability scale
)

print(ame)
Predictions at Specific Values
r
# Predictions at low (-1 SD), mean (0), and high (+1 SD)
predictions <- predictions(
  model,
  newdata = datagrid(
    model = model,
    predictor_z = c(-1, 0, 1)
  ),
  type = "response",
  re_formula = NA  # Population-level (ignore random effects)
)

as.data.frame(predictions) |>
  select(predictor_z, estimate, conf.low, conf.high)
Marginal Effect Plots
r
plot_predictions(
  model,
  by = "predictor_z",
  type = "response",
  re_formula = NA
) +
  labs(
    title = "Effect of Predictor on Outcome",
    x = "Predictor (standardized)",
    y = "P(Outcome)"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal()
Comparing Slopes Across Models
r
# Extract AME from multiple models
ame_model1 <- avg_slopes(model1, variables = "predictor_z", type = "response")
ame_model2 <- avg_slopes(model2, variables = "predictor_z", type = "response")

comparison <- bind_rows(
  as.data.frame(ame_model1) |> mutate(model = "Full"),
  as.data.frame(ame_model2) |> mutate(model = "Simple")
)

Model Diagnostics

Check MCMC Convergence
r
# Trace plots
mcmc_trace(model, pars = c("b_Intercept", "b_predictor_z"))

# R-hat (should be < 1.01)
summary(model)$fixed$Rhat

# Effective sample size (should be > 400)
summary(model)$fixed$Bulk_ESS
summary(model)$fixed$Tail_ESS
Posterior Predictive Checks
r
pp_check(model)
pp_check(model, type = "stat", stat = "mean")
pp_check(model, type = "stat_2d", stat = c("mean", "sd"))
Prior-Posterior Comparison
r
# Requires sample_prior = "yes" in brm()
prior_summary(model)

# Plot prior vs posterior
mcmc_areas(model, pars = "b_predictor_z", prob = 0.95)

tidybayes for Posterior Manipulation

r
# Extract draws in tidy format
draws <- model |>
  spread_draws(b_predictor1_z, b_predictor2_z) |>
  mutate(
    OR_predictor1 = exp(b_predictor1_z),
    OR_predictor2 = exp(b_predictor2_z)
  )

# Summarize
draws |>
  median_qi(OR_predictor1, OR_predictor2, .width = c(0.80, 0.95))

# Visualize
draws |>
  ggplot(aes(x = OR_predictor1)) +
  stat_halfeye() +
  geom_vline(xintercept = 1, linetype = "dashed") +
  labs(x = "Odds Ratio", y = NULL)

Workflow Summary

  1. Define causal DAG with dagitty
  2. Validate DAG against data with localTests()
  3. Identify adjustment sets for target effects
  4. Specify priors based on domain knowledge
  5. Fit brms model with random effects for nested data
  6. Check diagnostics (convergence, PPCs)
  7. Extract posteriors for inference
  8. Compute marginal effects on interpretable scale
  9. Visualize effects with uncertainty

Anti-Patterns to Avoid

r
# WRONG: Using contemporaneous predictors when temporal order matters
outcome_t ~ predictor_t  # Shows co-occurrence, not temporal precedence

# CORRECT: Use lagged predictors to establish temporal precedence
outcome_t ~ predictor_t_minus_1

# WRONG: Ignoring clustering
brm(outcome ~ predictor, data = longitudinal_data)

# CORRECT: Account for repeated measures
brm(outcome ~ predictor + (1 | participant_id), data = longitudinal_data)

# WRONG: Interpreting within-person effects from between-person variation
# Using person aggregates when you have time-varying data

# CORRECT: Person-mean centering to separate effects
outcome ~ predictor_mean_z + predictor_dev_z + (1 | id)

© ab604, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/r-bayes of ab604/claude-code-r-skills.

Open the folder on GitHubat commit 529de4f

Used in 2 other repositories

We found 2 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 2 other GitHub owners. This page covers the copy in ab604/claude-code-r-skills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

R Bayes next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

R Bayes compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
R Bayes this skillab604/claude-code-r-skills2072 repos~2.5kAutomated safety check: PassMIT
Ito Inferenceaffaan-m/ECC276k1 repos~1.5kAutomated safety check: PassMIT
Gke Inferencegoogle/skills21k—~2kAutomated safety check: PassApache-2.0
LLM Inference Scalingsickn33/agentic-awesome-skills47k1 repos~2.1kAutomated safety check: PassMIT
Debug InferenceNVIDIA/OpenShell16k—~1.9kAutomated safety check: PassApache-2.0
Bio Phylo Bayesian InferenceGPTomics/bioSkills1.2k1 repos~6.9kAutomated safety check: PassMIT

Similar skills

  • Ito Inference

    affaan-m/ECC

    Inspect the availability of model serving on a completed Itô compute booking and, when the canonical backend becomes available, hand off an explicitly confirmed serving manifest.

    276k GitHub starsUsed in 1 repo~1.5k tokens
    AI & LLM EngineeringAuto-check passed
  • Gke Inference

    google/skills

    Official

    Deploys and optimizes AI/ML inference workloads on GKE, using GPUs, TPUs, and model servers.

    21k GitHub stars~2k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • LLM Inference Scaling

    sickn33/agentic-awesome-skills

    Auto-scale LLM inference clusters on Kubernetes using KEDA, custom GPU metrics, and horizontal pod autoscaling.

    47k GitHub starsUsed in 1 repo~2.1k tokens
    AI & LLM EngineeringAuto-check passed
  • Debug Inference

    NVIDIA/OpenShell

    Official

    Debug inference clients that use an attached provider and its native endpoint, including hosted APIs and host-local Ollama, vLLM, SGLang, TRT-LLM, LM Studio, or NIM.

    16k GitHub stars~1.9k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Frames Bayesian phylogenetics as approximating a posterior distribution over trees conditioned on data AND priors via an MCMC that must be proven to have converged, using MrBayes, BEAST2, RevBayes…

    1.2k GitHub starsUsed in 1 repo~6.9k tokens
    Research & ScienceAuto-check passed
  • Type Inference

    biomejs/biome

    Official

    A skill your agent uses when working on Biome's Salsa-backed JavaScript and TypeScript inference, including type-aware lint rules, raw collection or inferred representations, analyzer requests…

    26k GitHub stars~2.6k tokensUpdated today
    DevelopmentAuto-check passed

More from ab604/claude-code-r-skills

All 8 skills in this repo
  • R Oop

    ab604/claude-code-r-skills

    R object-oriented programming guide for S7, S3, S4, and vctrs.

    207 GitHub starsUsed in 2 repos~1.9k tokens
    Auto-check passed
  • R Package Development

    ab604/claude-code-r-skills

    R package development guide covering dependencies, API design, testing, and documentation.

    207 GitHub starsUsed in 2 repos~2.4k tokens
    Auto-check passed
  • R Performance

    ab604/claude-code-r-skills

    R performance best practices including profiling, benchmarking, vctrs, and optimization strategies.

    207 GitHub starsUsed in 2 repos~2.4k tokens
    Auto-check passed
  • R Style Guide

    ab604/claude-code-r-skills

    R style guide covering naming conventions, spacing, layout, and function design best practices.

    207 GitHub starsUsed in 2 repos~1.7k tokens
    Auto-check passed
  • Rlang Patterns

    ab604/claude-code-r-skills

    rlang metaprogramming patterns for data-masking, injection operators, and dynamic dots.

    207 GitHub starsUsed in 2 repos~2.1k tokens
    Auto-check: notes
  • TDD Workflow

    ab604/claude-code-r-skills

    Test-driven development workflow for R using testthat. An agent skill from ab604/claude-code-r-skills.

    207 GitHub starsUsed in 2 repos~4.8k tokens
    Auto-check passed

Questions about R Bayes

What does R Bayes do?

Patterns for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects. R Bayes is an agent skill from ab604/claude-code-r-skills. Patterns for Bayesian inference in R using brms, including multilevel models, DAG validation, and marginal effects.

When should I use R Bayes?

R Bayes fits situations like: performing Bayesian analysis.

How do I install R Bayes in Claude Code?

Run `npx skills add ab604/claude-code-r-skills --skill r-bayes -a claude-code`. Or copy the skill folder (.claude/skills/r-bayes in ab604/claude-code-r-skills) into .claude/skills/r-bayes in your project. Claude Code loads it when a task matches its description.

How do I install R Bayes in Codex?

Run `npx skills add ab604/claude-code-r-skills --skill r-bayes -a codex`. Or copy the skill folder (.claude/skills/r-bayes in ab604/claude-code-r-skills) into .agents/skills/r-bayes in your project. Codex loads it when a task matches its description.

Can I use R Bayes in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ab604/claude-code-r-skills --skill r-bayes -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/r-bayes, .gemini/skills/r-bayes, .github/skills/r-bayes and .opencode/skills/r-bayes in your project.

What does R Bayes need to run?

SKILL.md names no scripts, command-line tools or credentials: R Bayes is instructions for the agent only.

Does R Bayes access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is R Bayes safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does R Bayes use?

R Bayes is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does R Bayes use?

About 2.5k tokens (SKILL.md is roughly 9.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to R Bayes?

Skills that share tags, products or a category with R Bayes: Ito Inference (affaan-m/ECC, 276k stars), Gke Inference (google/skills, 21k stars), LLM Inference Scaling (sickn33/agentic-awesome-skills, 47k stars) and Debug Inference (NVIDIA/OpenShell, 16k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains R Bayes?

ab604 (a GitHub user) maintains it in ab604/claude-code-r-skills, which has 207 GitHub stars. The repository holds 8 skills in this directory. The repository was last updated on September 17, 2026.

Source: ab604/claude-code-r-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.