Add log_posterior() and nuts_params() methods for draws objects#541
Add log_posterior() and nuts_params() methods for draws objects#541utkarshpawade wants to merge 1 commit intostan-dev:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for extracting log-posterior values and NUTS sampler diagnostics directly from posterior::draws_* objects, aligning extractor behavior with existing bayesplot plotting helpers that already accept draws objects.
Changes:
- Added S3 methods
log_posterior()andnuts_params()fordraws_array,draws_df, anddraws_matrix. - Refactored
CmdStanMCMCextractor methods to delegate to the newdraws_arrayimplementations. - Added tests, documentation aliases/usages, and a NEWS entry for the new extractor support.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
R/bayesplot-extractors.R |
Implements new draws_* S3 methods and delegates CmdStanMCMC methods to them. |
man/bayesplot-extractors.Rd |
Documents new S3 method aliases/usages for draws_* extractors. |
NAMESPACE |
Registers the new S3 methods for draws_array, draws_df, and draws_matrix. |
tests/testthat/test-extractors.R |
Adds coverage for structure + error behavior of new draws-object extractors. |
NEWS.md |
Announces new extractor methods for posterior::draws_* objects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #541 +/- ##
==========================================
- Coverage 99.15% 99.14% -0.02%
==========================================
Files 35 35
Lines 5920 5935 +15
==========================================
+ Hits 5870 5884 +14
- Misses 50 51 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for working on this, but I'm not sure it's needed. After thinking about this, I don't think these methods are the right fit for draws objects. The log_posterior() and nuts_params() extractors are designed to pull specific quantities out of opaque fitted model objects. In practice, if you have a draws object from cmdstanr (via fit$draws()), then you also have the CmdStanMCMC fit object, so you can just use nuts_params(fit) and log_posterior(fit) directly. I'm going to close this along with #540. |
Fixes #540
log_posterior()andnuts_params()methods fordraws_array,draws_df, anddraws_matrixobjects from theposteriorpackage.CmdStanMCMCmethods to delegate to the newdraws_arraymethods (no behavior change).