Statistics
Verification
Reference comparisons
On this page
Specifications
Export
Scope
Predictions with confidence intervals, marginal means with confidence intervals, and random-effect conditional modes and standard deviations. Identical model formulas and data across implementations.
References
- Reference
- R 4.6.1: lm(), predict(); lme4 2.0.6: lmer(), ranef(condVar = TRUE)
- Versions
- R 4.6.1, lme4 2.0.6, phit-polyfill v0.4.1
Data
- mtcars
- 32 rows, R's datasets package
- mpg
- 234 rows, ggplot2 4.0.3
Method
scripts/evidence/r-references.R fits the models in R and lme4 and writes tests/fixtures/r-references.json. scripts/evidence/parity.php fits the same models with phit, passes the fits to predictions(), marginal_means(), and random_effects_plot(), and compares the results value by value.
- Check
- Comparison with a reference implementation
- Recorded
- 2026-11-02, PHP 8.5.11, Debian GNU/Linux 13 (trixie) (aarch64), commit b9272c6
Tolerances
|x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12)
Applies to: Numerical results
Fits, quantiles, intervals, and polygon points
|x − r| ≤ 1e-6 + 1e-6 × max(|r|, 1e-12)
Applies to: Mixed-model conditional modes and standard deviations
Dependent on the REML optimum
x: package value; r: reference value. Absolute error: |x − r|. Relative error: |x − r| / max(|r|, 1e-12). Max errors are over the values a row compares.
Results
4 comparisons in 3 cases: 4 pass, 0 fail, 0 skipped.
By case
| Case | Comparisons | Largest abs. error | Largest rel. error | Status |
|---|---|---|---|---|
| mtcars, mpg ~ wt + hp + factor(cyl) | 1 | 3.9e-14 | 1.9e-15 | pass |
| mtcars, mpg ~ factor(cyl) + factor(am) + wt | 1 | 3.2e-14 | 1.5e-15 | pass |
| mpg, hwy ~ displ + (1 | manufacturer) | 2 | 2.0e-7 | 2.2e-7 | pass |
Every comparison
| Case | Quantity | Criterion | Values | Max abs. error | Max rel. error | Status |
|---|---|---|---|---|---|---|
| mtcars, mpg ~ wt + hp + factor(cyl) | predictions on a 9-row grid: estimate, lower, upper | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 27 | 3.9e-14 | 1.9e-15 | pass |
| mtcars, mpg ~ factor(cyl) + factor(am) + wt | marginal means of cyl: estimate, lower, upper | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 9 | 3.2e-14 | 1.5e-15 | pass |
| mpg, hwy ~ displ + (1 | manufacturer) | conditional modes of 15 manufacturers | |x − r| ≤ 1e-6 + 1e-6 × max(|r|, 1e-12) | 15 | 2.0e-7 | 2.2e-7 | pass |
| conditional standard deviations of 15 manufacturers | |x − r| ≤ 1e-6 + 1e-6 × max(|r|, 1e-12) | 15 | 5.8e-8 | 4.1e-8 | pass |
Limitations
Exclusions
- The fits come from phit-polyfill; the cases test phiz's helpers together with phit's fits. phit's fits are verified separately.
- Marginal means are compared with the emmeans formula computed directly in R; the emmeans package is not used.
Reproduction
Rscript scripts/evidence/r-references.R
php scripts/evidence-parity.php
- Raw record
- site/verifications/r-statistics.json
- Full results
- site/verifications/r-statistics.json
- Input data
- tests/fixtures/r-references.json