Skip to content

[v0.4.x] Add exponential distribution to the native backend (legacy parity) #37

Description

@DougManuel

Part of the post-v0.4.0 development plan (development/post-v040-development-plan.md, Phase 1, Task 4).

Context — this is a parity gap, not a new feature

  • The legacy generator supports exponential: R/create_con_var.R:279-281 (rexp(n_valid, rate = rate_val)), documented in advanced-topics and the metadata schema (rate column).
  • The native v0.4 backend stops: R/mock_spec_native.R:202-208 ("Native backend does not yet support continuous distribution 'exponential'...") — so exponential metadata forces the v0.4→legacy fallback (which also switches RNG streams, Follow-ups from PR #32 review: loader validation, strict-mode semantics, doc polish #33 item 11).
  • The plumbing already exists: the recodeflow adapter stores rate on the spec variable (R/mock_spec_recodeflow.R:365), and .new_mock_spec_variable() forwards extra fields via ....

Scope

  1. Add rate = NA_real_ parameter to mock_continuous() and mock_spec_continuous(), forwarded to .new_mock_spec_variable().
  2. Validator rule in .validate_mock_spec_variable() (next to the existing normal-distribution block at R/mock_spec.R:792-798): distribution == "exponential" requires rate > 0.
  3. .generate_native_continuous() branch using inverse-CDF truncation to the declared range (qexp(runif(n, pexp(lo, rate), pexp(hi, rate)), rate)), mirroring .native_truncated_normal().
  4. Document the intentional semantic difference: legacy rexp() is unbounded; native truncates to the declared range, consistent with the native normal. NEWS entry.

Out of scope: simstudy-backend exponential mapping; distribution registry (see plan, deferred register).

Acceptance

Relates to #24.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Nice to have, lower urgency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions