Skip to contents

bmstate 0.4.0

  • Correct the baseline-hazard prior scale. The public model API stores baseline-hazard reference values as natural-scale rates, but these values were passed directly to a Stan parameter used as the location of log_w0. For example, a reference rate of 0.001 therefore centered the hazard near exp(0.001) = 1.001, rather than 0.001. Stan data creation now applies log() exactly once at the R–Stan boundary. The default Stan data field is consequently renamed from mu_w0 to mu_log_w0; custom Stan programs selected with options(bmstate_stan_file = ...) must adopt the new name. Fits produced by affected versions must be rerun.

  • Make transition support and baseline-hazard calibration explicit. The previous cumulative-hazard summary silently omitted modeled transitions with no events, which could leave empirical prior locations undefined and defer failure until Stan data were validated. Fit-time validation now stops with the affected transition names if any transition in the fitted matrix has no observed occurrence or no positive at-risk time. This check is deliberately not applied to out-of-sample prediction data. For valid transition systems, reference rates are computed from event counts divided by exact at-risk time, pooled within transition type. Documentation now calls the calibrated quantity a natural-scale reference rate, not an arithmetic prior mean.

  • Preserve joint posterior-draw alignment in prediction. Replicating the baseline-hazard arrays previously produced a different draw/subject ordering from the hazard multipliers and prediction metadata, so parameters from one posterior draw could be combined with another. The package now constructs an explicit draw-major row index and uses the same ordering for spline weights, log intercepts, subject multipliers, path links, and occupancy calculations.

  • Retain zero state-visit probabilities. p_state_visit() previously built its output only from observed event rows, silently dropping requested subjects or groups with no visit to an event state. It now completes the state-by-group grid, joins event counts and denominators separately, and returns explicit zero counts and probabilities.

  • Keep simulated paths inside the requested horizon. Applying min_t_step could move a genuine event beyond t_max; the final-row cleanup then relabeled that row as censoring without clearing its transition index. Event-time adjustment now preserves a genuine pre-horizon event when the adjustment would cross the horizon, every censor row has transition index zero, invalid reversed horizons are rejected, and a zero-length horizon returns a valid one-row censored path.

  • Stabilize the oral one-compartment PK solution near equal rates. Direct evaluation divided by ka - ke and could produce cancellation, 0 / 0, or 0 * Inf when absorption and elimination rates were equal or very different. The transient solution now uses sign-aware expm1() factorizations, and the transient and steady-state solutions use their continuous equal-rate limits in a small numerical guard region. The limit uses the ka prefactor so that both the value and first derivative match at equality to first order.

  • Construct exactly the requested integration grid. For a noninteger maximum time, the old seq(..., ceiling(t_max), by = delta) expression could generate more than N_grid points and make the declared Stan dimensions disagree with the supplied arrays. The grid is now formed directly from exactly N_grid midpoint indices.

  • Honor delayed starts in transition-probability prediction. solve_trans_prob_matrix() previously initialized the forward equation at the first output time, even when an earlier t_start was requested. It now includes t_start in the integration times, returns only the requested output rows, and validates times and hazard-parameter dimensions even on the zero-duration identity path.

  • Return the requested PK credible-interval width. The plotting helper divided the tail probability by two twice, so an 80% request used the 5th and 95th percentiles and returned a 90% interval. It now uses (1 - ci_alpha) / 2 and its complement directly.

  • Reduce reverse-mode work for time-invariant hazard predictors. The Stan program previously expanded subject covariates to every interval and, before hoisting, rebuilt the complete multiplier matrix inside each transition loop. It now differentiates one predictor per subject and transition type, then gathers those values for the relevant intervals. This is algebraically identical and reduced gradient time by about 38% in a representative benchmark with many intervals, with no measured regression when every interval belonged to a different subject.

  • Tighten edge-case validation and output construction. The release adds checks for positive PK rates, dosing intervals, concentration bounds, and exposure-normalization scales; rejects malformed delayed-start requests; handles base data frames without accidental dimension dropping; and builds simulated path output in a list before binding it once.