Model methods
Verification
Comparisons with R
- CmdStanR methods
- Posterior summaries
- LOO and PSIS
- Moment matching
- Model methods
- Stan functions
- Figures
- rvars and inits
- Metadata
On this page
Comparisons with other interfaces
Scope
Log density, gradient, Hessian, constrained and unconstrained values, unconstrained draws, and variable dimensions, evaluated in process through FFI. Identical program, data, and evaluation points.
References
- Reference
- cmdstanr 0.99.0 (commit 0a54123) model methods, compiled with Rcpp 1.1.2 and RcppEigen 0.3.4.0.2
- Versions
- PHP 8.5.10, CmdStan 2.40.0, R 4.6.1, cmdstanr 0.99.0 (commit 0a54123), Rcpp 1.1.2, RcppEigen 0.3.4.0.2
Data
- Inputs
- tests/fixtures/native.stan (constrained scalars, a matrix, a simplex, and a covariance matrix) with N = 4, at one point of 19 unconstrained values, and at draws from CmdStanR.
Method
CmdStanPHP and CmdStanR each compile tests/fixtures/native.stan with model methods and evaluate them at the same points.
- Check
- Comparison with a reference implementation
- Recorded
- 2026-11-02, PHP 8.5.10, macOS 27.0.1 (arm64), commit 4ec6712
Tolerances
|x − r| ≤ 1e-12
Applies to: Constrained and unconstrained values
|x − r| ≤ 1e-10
Applies to: Log densities, gradients, and unconstrained draws
|x − r| ≤ 1e-8
Applies to: Hessian gradient
|x − r| ≤ 1e-6
Applies to: Hessian matrix
exact equality
Applies to: Names and dimensions
x: package value; r: reference value. Absolute error: |x − r|. Relative error: |x − r| / max(|r|, 1). Max errors are over the values a row compares.
Results
15 comparisons in 2 cases: 15 pass, 0 fail, 0 skipped.
By case
| Case | Comparisons | Largest abs. error | Largest rel. error | Status |
|---|---|---|---|---|
| native.stan, 19 unconstrained values | 14 | 4.3e-14 | 3.2e-15 | pass |
| native.stan, CmdStanR draws | 1 | 6.5e-15 | 6.5e-15 | pass |
Every comparison
| Case | Quantity | Criterion | Values | Max abs. error | Max rel. error | Status |
|---|---|---|---|---|---|---|
| native.stan, 19 unconstrained values | log_prob() | |x − r| ≤ 1e-10 | 1 | 4.3e-14 | 3.2e-15 | pass |
| log_prob() without Jacobian | |x − r| ≤ 1e-10 | 1 | 1.1e-14 | 8.7e-16 | pass | |
| grad_log_prob() log density | |x − r| ≤ 1e-10 | 1 | 4.3e-14 | 3.2e-15 | pass | |
| grad_log_prob() gradient | |x − r| ≤ 1e-10 | 19 | 2.2e-15 | 9.5e-16 | pass | |
| grad_log_prob() without Jacobian log density | |x − r| ≤ 1e-10 | 1 | 1.1e-14 | 8.7e-16 | pass | |
| grad_log_prob() without Jacobian gradient | |x − r| ≤ 1e-10 | 19 | 2.2e-15 | 9.5e-16 | pass | |
| hessian() log density | |x − r| ≤ 1e-10 | 1 | 4.3e-14 | 3.2e-15 | pass | |
| hessian() gradient | |x − r| ≤ 1e-8 | 19 | 2.2e-15 | 9.5e-16 | pass | |
| hessian() matrix | |x − r| ≤ 1e-6 | 361 | 4.0e-15 | 2.9e-15 | pass | |
| unconstrain_variables() | |x − r| ≤ 1e-12 | 19 | 4.4e-16 | 4.4e-16 | pass | |
| constrain_variables() names | exact equality | 7 | pass | |||
| constrain_variables() values | |x − r| ≤ 1e-12 | 22 | 8.9e-16 | 4.9e-16 | pass | |
| variable_skeleton() | exact equality | 12 | pass | |||
| unconstrained parameter names | exact equality | 19 | pass | |||
| native.stan, CmdStanR draws | unconstrain_draws() | |x − r| ≤ 1e-10 | 95 | 6.5e-15 | 6.5e-15 | pass |
Reproduction
php verification/compatibility/run.php
- Raw record
- site/verifications/model-methods.json
- Full results
- verification/compatibility/results.json