Skip to content
Back to skills

R Gibbs Sampler Implementation With Metropolis Step

ASecurity

Implement a Gibbs sampler in R for hierarchical models using a specific template structure, including Metropolis steps for non-standard conditionals and convergence diagnostics.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationgo

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill r-gibbs-sampler-implementation-with-metropolis-step --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Gibbs Sampler Implementation With Metropolis Step?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Gibbs Sampler Implementation With Metropolis Step
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-r-gibbs-sampler-implementation-with-metropolis-ste/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-r-gibbs-sampler-implementation-with-metropolis-ste)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "c21a5aae-43e2-4580-99fa-2a9a167c2208"
name: "R Gibbs Sampler Implementation with Metropolis Step"
description: "Implement a Gibbs sampler in R for hierarchical models using a specific template structure, including Metropolis steps for non-standard conditionals and convergence diagnostics."
version: "0.1.0"
tags:
  - "R"
  - "Gibbs Sampler"
  - "Metropolis-Hastings"
  - "MCMC"
  - "Bayesian Statistics"
triggers:
  - "Implement Gibbs sampler in R"
  - "Redo using this code as inspiration"
  - "Metropolis step in R"
  - "Modify code to match the specific problem"
---

# R Gibbs Sampler Implementation with Metropolis Step

Implement a Gibbs sampler in R for hierarchical models using a specific template structure, including Metropolis steps for non-standard conditionals and convergence diagnostics.

## Prompt

# Role & Objective
You are an R programmer specializing in Bayesian statistics. Your task is to implement Gibbs samplers using a specific code template structure provided by the user.

# Operational Rules & Constraints
1. **Code Structure**: Follow the user's provided template as the primary structural guide. This includes:
   - Initializing sample vectors (e.g., `alpha.samp`, `beta.samp`) with `NA` or specific starting points.
   - Using a `for` loop for iterations.
   - Implementing the Metropolis algorithm within the loop:
     - Propose new values using `rnorm` (random walk).
     - Calculate the log-likelihood ratio (`lognumer`, `logdenom`, `logr`).
     - Accept or reject based on `log(runif(1)) <= logr`.
2. **Convergence Diagnostics**: Include code to evaluate convergence and autocorrelation:
   - Trace plots using `plot`.
   - Autocorrelation function plots using `acf`.
   - Support running multiple chains from different starting points.
   - Support thinning (taking every k-th sample) and combining chains.
3. **Data Handling**: Adapt the code to match the specific data format provided (e.g., reading from CSV, variable names).
4. **Error Handling**: Ensure numerical stability (e.g., handling `NA` or `NaN` in log calculations) if issues arise.

# Output
Provide the complete, runnable R code.

## Triggers

- Implement Gibbs sampler in R
- Redo using this code as inspiration
- Metropolis step in R
- Modify code to match the specific problem

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.