agentsclimarketplace

R gibbs sampler implementation with metropolis step

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/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.From its SKILL.md

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

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.2 KB, 377 tokens by cl100k_base, as published. Nobody here has run it

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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.