Distributions
Verification
Reference comparisons
On this page
Specifications
Export
Scope
Normal and t quantiles, sample quantiles, bandwidths, two-dimensional density grids, contour levels and pieces, confidence ellipses, mean_cl_normal intervals, and violin densities. Identical data across implementations.
References
- Reference
- R 4.6.1, MASS 7.3.65, ggplot2 4.0.3
- Versions
- R 4.6.1, MASS 7.3.65, ggplot2 4.0.3
Data
- faithful
- 272 rows, R's datasets package
- mtcars
- 32 rows, R's datasets package
- mpg
- 234 rows, ggplot2 4.0.3
Method
scripts/evidence/r-references.R computes the reference values with R, MASS, and ggplot2 and writes tests/fixtures/r-references.json. scripts/evidence/parity.php computes the same quantities with phiz and compares them 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-12 + 1e-9 × max(|r|, 1e-12)
Applies to: Density grid
Tails reach 1e-30
|x − r| ≤ 0.001
Applies to: Relative density heights
exact equality
Applies to: Counts, levels, piece sizes, and colors
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
17 comparisons in 8 cases: 17 pass, 0 fail, 0 skipped.
By case
| Case | Comparisons | Largest abs. error | Largest rel. error | Status |
|---|---|---|---|---|
| fixed probabilities | 3 | 2.8e-14 | 2.2e-15 | pass |
| mtcars wt | 2 | 0 | 0 | pass |
| faithful | 6 | 2.7e-13 | 1.1e-14 | pass |
| mpg displ and hwy | 1 | 7.1e-14 | 2.4e-14 | pass |
| mtcars wt and mpg | 1 | 1.4e-14 | 7.6e-16 | pass |
| 1512 random and edge-case ranges | 1 | 4.4e-16 | 3.7e-15 | pass |
| mpg hwy by class | 1 | 7.1e-15 | 2.5e-16 | pass |
| faithful eruptions | 2 | 6.8e-5 | 2.5e-4 | pass |
Every comparison
| Case | Quantity | Criterion | Values | Package value | Reference value | Max abs. error | Max rel. error | Status |
|---|---|---|---|---|---|---|---|---|
| fixed probabilities | qnorm() at 3 probabilities | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 3 | 8.9e-16 | 2.9e-16 | pass | ||
| qt() at 4 probabilities and degrees of freedom | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 4 | 2.8e-14 | 2.2e-15 | pass | |||
| pnorm() | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 1 | 0.975 | 0.975 | 0 | 0 | pass | |
| mtcars wt | type 7 quantiles at 0.05, 0.25, 0.9 | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 3 | 0 | 0 | pass | ||
| bw.nrd0 bandwidth | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 1 | 0.3454757463 | 0.3454757463 | 0 | 0 | pass | |
| faithful | kde2d grid coordinates | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 200 | 1.4e-14 | 2.2e-16 | pass | ||
| kde2d density on the 100 × 100 grid | |x − r| ≤ 1e-12 + 1e-9 × max(|r|, 1e-12) | 10,000 | 5.6e-17 | 1.1e-14 | pass | |||
| density contour levels | exact equality | 12 | pass | |||||
| points in each contour piece at level 0.002 | exact equality | 3 | pass | |||||
| stat_ellipse(type = "t") polygon x and y | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 104 | 2.8e-14 | 3.0e-15 | pass | |||
| stat_ellipse(type = "norm") polygon x and y | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 104 | 2.7e-13 | 8.4e-15 | pass | |||
| mpg displ and hwy | stat_ellipse(type = "t") polygon x and y | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 104 | 7.1e-14 | 2.4e-14 | pass | ||
| mtcars wt and mpg | stat_ellipse(type = "t") polygon x and y | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 104 | 1.4e-14 | 7.6e-16 | pass | ||
| 1512 random and edge-case ranges | pretty() breaks, scaled by their largest value | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 22,102 | 4.4e-16 | 3.7e-15 | pass | ||
| mpg hwy by class | mean_cl_normal mean, lower, and upper for 7 classes | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 21 | 7.1e-15 | 2.5e-16 | pass | ||
| faithful eruptions | violin evaluation points | |x − r| ≤ 1e-9 + 1e-9 × max(|r|, 1e-12) | 5 | 0 | 0 | pass | ||
| violin widths against density() heights, relative to the largest | |x − r| ≤ 0.001 | 5 | 6.8e-5 | 2.5e-4 | pass |
Limitations
Exclusions
- Violin widths are compared as relative heights. phiz scales each violin to its band, so absolute densities are not part of the output.
Known differences
- R's density() approximates the kernel sum with an FFT over a binned grid; phiz evaluates the kernel sum exactly. Relative heights differ by about 1e-4.
Reproduction
Rscript scripts/evidence/r-references.R
php scripts/evidence-parity.php
- Raw record
- site/verifications/r-distributions.json
- Full results
- site/verifications/r-distributions.json
- Input data
- tests/fixtures/r-references.json