Skip to content

Add log_posterior() and nuts_params() methods for draws objects#541

Closed
utkarshpawade wants to merge 1 commit intostan-dev:masterfrom
utkarshpawade:fix/extractors-draws-support
Closed

Add log_posterior() and nuts_params() methods for draws objects#541
utkarshpawade wants to merge 1 commit intostan-dev:masterfrom
utkarshpawade:fix/extractors-draws-support

Conversation

@utkarshpawade
Copy link
Copy Markdown
Contributor

Fixes #540

  • Adds log_posterior() and nuts_params() methods for draws_array, draws_df, and draws_matrix objects from the posterior package.
  • Refactors existing CmdStanMCMC methods to delegate to the new draws_array methods (no behavior change).

Copilot AI review requested due to automatic review settings April 15, 2026 14:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() and nuts_params() for draws_array, draws_df, and draws_matrix.
  • Refactored CmdStanMCMC extractor methods to delegate to the new draws_array implementations.
  • 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-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.14%. Comparing base (44c3e5c) to head (56abf4b).

Files with missing lines Patch % Lines
R/bayesplot-extractors.R 95.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jgabry
Copy link
Copy Markdown
Member

jgabry commented Apr 15, 2026

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.

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.

Extractors log_posterior() and nuts_params() don't accept posterior draws objects

4 participants