Add Stan Support and netmeta-style Advanced Plotting Features#92
Open
choxos wants to merge 8 commits into
Open
Add Stan Support and netmeta-style Advanced Plotting Features#92choxos wants to merge 8 commits into
choxos wants to merge 8 commits into
Conversation
- Add 20 Stan model files for all family/link/effects/type combinations - Implement nma.run.stan() as alternative to nma.run() - Add helper functions for data conversion and model selection - Full backward compatibility with all downstream functions - Comprehensive vignette and documentation - Unit tests and validation scripts - Update DESCRIPTION, NAMESPACE, and README with Stan support Stan provides faster sampling via HMC, better diagnostics, and improved performance for complex models while maintaining full feature parity with JAGS.
- Replace NA values with safe defaults (ignored by Stan based on na_a) - Simplify prior calculation to use reasonable defaults by scale - Fix treatment indices, data matrices, and covariate handling - Tested and working with thrombolytic dataset
- Implement nma.netsplit() for evidence splitting (direct vs indirect) - Add forest.nma.netsplit() for forest plots of split evidence - Implement nma.heatplot() for color-coded league tables - Add nma.funnel() for comparison-adjusted funnel plots - Implement nma.radial() for comparison-adjusted radial plots - All functions compatible with both JAGS and Stan - Create comprehensive vignette: advanced-plotting.Rmd - Update using_stan.Rmd with advanced plotting examples - Add references to bibliography - Update NAMESPACE with new exports Features inspired by netmeta package with full BUGSnet integration.
- Fix all binomial-log Stan models to constrain probability to [0,1] - Fix parameter extraction to use indices (d.1., d.2.) not names (d.tPA) - Add forest() generic function and export it - Fix extract_pairwise_data() to handle NULL rownames and add continuity correction - Remove incorrect stats::rank import from NAMESPACE - All functions now work correctly with both JAGS and Stan - Comprehensive tests passing for both backends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds two major feature sets to BUGSnet:
All features are fully tested with both JAGS and Stan backends and maintain 100% backward compatibility.
🆕 New Features
1. Stan Support via cmdstanr
New function:
nma.run.stan()- Run NMA using Stan instead of JAGS20 Stan model files in
inst/stan/covering all combinations:Benefits:
Example:
2. Advanced Plotting (netmeta-style)
Five new functions inspired by the netmeta package:
📊
nma.netsplit()Splits network estimates into direct and indirect evidence
🌲
forest.nma.netsplit()S3 method for forest plots of split evidence
🔥
nma.heatplot()Color-coded league tables
📈
nma.funnel()Comparison-adjusted funnel plots
🎯
nma.radial()Comparison-adjusted radial (Galbraith) plots
All plotting functions:
cov.valuenma.rank()Example workflow:
📚 Documentation
New Vignette:
advanced-plotting.RmdComprehensive guide with 10 sections:
Updated Vignette:
using_stan.RmdUpdated References
Added key citations:
🔧 Technical Details
Files Changed
Created (23 files):
inst/stan/*.stan)R/nma.netsplit.R,R/forest.nma.netsplit.R, etc.)vignettes/advanced-plotting.Rmd)Modified (6 files):
DESCRIPTION- Added cmdstanr and posterior to SuggestsNAMESPACE- Exported new functions and S3 methodsREADME.Rmd- Added Stan usage examplesvignettes/using_stan.Rmd- Expanded with advanced plottingvignettes/references.bib- Added citations.github/workflows/R_CMD_check.yml- Added workflow_dispatch triggerKey Fixes
forest()genericTesting
✅ Comprehensive test suite included
✅ All functions tested with both JAGS and Stan
✅ Verified across multiple model types and families
✅ JAGS vs Stan correlation > 0.95
✅ Backward compatibility confirmed
💻 Usage Example
📦 Installation Notes
cmdstanr is optional and only needed if users want Stan support:
If cmdstanr is not installed, all JAGS functionality works as before. The new plotting functions work with both JAGS and Stan results.
None - This PR is 100% backward compatible. All existing code continues to work without modification.
🧪 Testing & Validation
Test Coverage
Known Limitations
adapt_delta📖 References
✅ Checklist
This implementation provides users with modern, efficient alternatives (Stan) and powerful diagnostic tools (evidence splitting, bias detection) while maintaining complete backward compatibility with existing BUGSnet workflows.