Skip to content

Fix pda.create.btprior() support for exponential priors - #4328

Open
pranshup04 wants to merge 1 commit into
PecanProject:developfrom
pranshup04:fix-btprior-exponential
Open

pranshup04 wants to merge 1 commit into
PecanProject:developfrom
pranshup04:fix-btprior-exponential

Conversation

@pranshup04

@pranshup04 pranshup04 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes PEcAn.assim.batch::pda.create.btprior() so it can construct exponential ("exp") priors alongside two-parameter priors.

Reproduction & Cause

On develop (ccaf2c2a24), constructing an exponential prior fails immediately with unused argument (b):

library(PEcAn.assim.batch)
prior_df <- data.frame(
  param_name = "x",
  distn = "exp",
  parama = 2,
  paramb = NA_real_
)
prior <- pda.create.btprior(prior_df)
# Error in f(n, a, b) : unused argument (b)

ddist_generator() and rdist_generator() in modules/assim.batch/R/pda.bayestools.helpers.R unconditionally passed both a and b to match.fun(paste0("d", distn)) and match.fun(paste0("r", distn)). While pda.define.prior.fn() (pda.utils.R) and plot.da.R already handle distn == "exp" without paramb, pda.bayesian.tools() subsequently passes the selected priors to pda.create.btprior(), where rexp() (called during BayesianTools::createPrior()) and dexp() reject the extra b argument.

Changes

  • Targeted fix (modules/assim.batch/R/pda.bayestools.helpers.R): Omit the unused b (paramb) argument in ddist_generator() and rdist_generator() when as.character(distn) == "exp", and remove the resolved TODO comment. Two-parameter distributions and distributions accepting an optional noncentrality parameter (chisq, t) continue receiving b unchanged. Discrete one-parameter distributions (pois, geom) are intentionally left out of this PR's scope.
  • Regression tests (modules/assim.batch/tests/testthat/test.bt_prior.R): Added coverage for "exp" priors with paramb = NA_real_ and paramb = 0 (verifying dexp(..., log = TRUE) log-density and rexp() sample mean/variance), mixed norm + exp priors, and chisq + t noncentrality preservation with paramb = 0.
  • Release notes (CHANGELOG.md, modules/assim.batch/NEWS.md): Documented the fix under PEcAn.assim.batch 1.9.1.9000 and Unreleased -> Fixed.

Validation

  • Installed PEcAn.assim.batch (R CMD INSTALL --no-multiarch) and ran testthat::test_local() in an offline PEcAn Docker container (R 4.4.3, BayesianTools installed): [ FAIL 0 | WARN 0 | SKIP 0 | PASS 23 ] (test.autoburnin.R: 7, test.bt_prior.R: 16).
  • Smoke-tested PEcAnRTM::prospect_bt_prior("4", ...) with an exponential N prior (sampler() returned a valid 5-parameter draw).
  • Ran git diff --cached --check cleanly. Full monorepo test suites and live BETY/MCMC workflow runs were not executed.

Motivation and Context

Exponential priors are already explicitly supported elsewhere in PEcAn.assim.batch (pda.define.prior.fn(), plot.da.R) and in PEcAn.utils::distn.stats(), and are reached directly from pda.bayesian.tools(). This PR aligns pda.create.btprior() with the rest of the package without altering existing two-parameter or optional-ncp behavior.

Review Time Estimate

  • Immediately
  • Within one week
  • When possible

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • My name is in the list of CITATION.cff
  • I agree that PEcAn Project may distribute my contribution under any or all of
    • the same license as the existing code,
    • and/or the BSD 3-clause license.
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

- Omit unused paramb argument when constructing dexp/rexp closures in pda.create.btprior(), preserving two-parameter and optional-ncp distributions (chisq, t).

- Add regression tests for exponential priors (NA and 0 paramb), mixed normal+exp priors, and chisq/t noncentrality preservation.

- Update CHANGELOG.md and modules/assim.batch/NEWS.md.
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.

1 participant