Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Implements Stan/cmdstanr support alongside existing JAGS implementation, allowing users to choose their preferred Bayesian MCMC backend.

Changes

Stan Model Files

  • inst/extdata/model.stan - Main antibody dynamics model with:
    • Precision→covariance matrix conversions (JAGS uses precision, Stan uses covariance)
    • Wishart→inverse Wishart transformation for subject-level variance priors
    • Explicit block structure (data, parameters, transformed parameters, model)
    • Conditional infection phase logic (active vs recovery) using if/else instead of JAGS step()
  • inst/extdata/model.dobson.stan - Simple Bernoulli example

R Functions

  • run_mod_stan() - Stan equivalent of run_mod(), returns same sr_model output format
  • prep_data_stan() - Handles Stan array padding requirements (no ragged arrays)
  • prep_priors_stan() - Prior specification interface matching prep_priors()

Dependencies

  • Added cmdstanr to Suggests (not Imports) - Stan support is optional
  • Runtime check with informative error if cmdstanr unavailable

Usage

# Existing JAGS workflow (unchanged)
run_mod(data, file_mod = "model.jags", nchain = 4, nadapt = 100, niter = 1000)

# New Stan workflow (identical interface)
run_mod_stan(data, file_mod = "model.stan", nchain = 4, nadapt = 500, niter = 1000)

Both return compatible outputs for existing analysis/plotting functions.

Installation (Stan)

install.packages("cmdstanr", repos = c("https://stan-dev.r-universe.dev", getOption("repos")))
cmdstanr::install_cmdstan()

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.r-project.org
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R /opt/R/4.5.2/lib/R/bin/exec/R -e install.packages('cmdstanr',~+~repos~+~=~+~c('REDACTED',~+~'REDACTED')) (dns block)
  • stan-dev.r-universe.dev
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R /opt/R/4.5.2/lib/R/bin/exec/R -e install.packages('cmdstanr',~+~repos~+~=~+~c('REDACTED',~+~'REDACTED')) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>convert jags model to stan</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 9, 2026 19:51
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert JAGS model to STAN Add Stan support as alternative Bayesian modeling backend Jan 9, 2026
Copilot AI requested a review from d-morrison January 9, 2026 20:03
@d-morrison d-morrison requested review from sschildhauer and removed request for sschildhauer January 10, 2026 10:10
Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix failing workflow checks

Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address workflow check failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert jags model to stan

2 participants