Download the PHP package cjuol/statguard without Composer

On this page you can find all versions of the php package cjuol/statguard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package statguard

🛡️ StatGuard: Robust Statistics & Data Integrity for PHP

[English] | Español

Latest Stable Version PHP Tests Coverage Docs Performance R-Compatibility PHP 8.x

StatGuard is a robust statistical analysis suite for PHP focused on scientific precision and data integrity. It compares classic statistics against robust statistics to detect bias, noise, and measurement anomalies in a fully automated way.

Why StatGuard

Outliers are inevitable in telemetry, finance, sports tracking, and lab measurements. A single extreme value can pull the arithmetic mean far from the central mass, which biases decisions that depend on it. StatGuard provides robust estimators (median, MAD, trimmed and winsorized means, Huber M-estimator) that stay stable under contamination so you can trust summaries even when the data is messy.

Highlights

Features

Installation

Install via Composer:

Interactive Demo

An Outlier Playground is shipped in web/public/. It renders a dataset, injects synthetic outliers on demand, and shows classic vs. robust estimators (mean, median, Huber, trimmed, winsorized) side by side with a histogram overlay and the StatsComparator verdict.

docker compose up -d brings up only the demo service (PHP built-in server on web/public/). Override the bind with STATGUARD_DEMO_BIND=0.0.0.0 STATGUARD_DEMO_PORT=8080 docker compose up -d if you are not fronting it with a reverse proxy. The legacy Apache service is kept under the apache profile (docker compose --profile apache up web).

The UI calls POST /api.php with {"data": [...], "huberK": 1.345, "trimPercent": 0.1} and returns the full summary as JSON, making it a usable backend endpoint on its own.

Usage

Robust Estimators (Quick Start)

Robust estimators stay stable even with extreme outliers:

Metric Result Comment
Arithmetic Mean 95.9091 Pulled up by the outlier
Huber Mean 6.0982 Stays close to the central mass

Example: Huber Mean

Example: Winsorized Mean (R-Compatible Quantile Type)

Comparator (Bias Detection)

Instant Export

Summary Keys (Classic vs Robust)

Classic summary keys:

Robust summary keys:

Metrics Comparison

Metric ClassicStats RobustStats Outlier Impact
Center Mean Median High in classic
Dispersion Standard Deviation MAD (Scaled) Extreme in classic
Variability CV% Robust CV% Very high in classic
Exportable ✅ Yes ✅ Yes -

R Quantile Types (1-9)

StatGuard matches R v4.x quantile definitions. The table below summarizes the nine Hyndman & Fan (1996) types supported by quantile().

Type $p_k$ $a$ $b$ Notes
1 $k / n$ 0 0 Inverse of empirical CDF (discontinuous).
2 $k / n$ 0 0 Averaged at discontinuities.
3 $(k - 0.5) / n$ -0.5 0 Nearest order statistic.
4 $k / n$ 0 1 Linear interpolation of CDF.
5 $(k - 0.5) / n$ 0.5 0.5 Hazen (1914).
6 $k / (n + 1)$ 0 1 Weibull (1939).
7 $(k - 1) / (n - 1)$ 1 1 R default, mode of $F(x)$.
8 $(k - 1/3) / (n + 1/3)$ 1/3 1/3 Median-unbiased.
9 $(k - 3/8) / (n + 1/4)$ 3/8 3/8 Normal-unbiased.

Implemented Methods

ClassicStats

RobustStats

StatsComparator

Mathematical Basis

Scaled Robust Deviation

To keep comparisons fair, MAD is scaled to be comparable to standard deviation under normal distributions:

$$\sigma_{robust} = MAD \times 1.4826$$

Robust Coefficient of Variation ($CV_r$)

Calculated over the median to avoid a single extreme value inflating volatility:

$$CVr = \left( \frac{\sigma{robust}}{|\tilde{x}|} \right) \times 100$$

R Compatibility & Accuracy

Every public statistic is tested against R v4.x outputs to ensure scientific accuracy. Quantile calculations use Type 7 by default (the same default as quantile() in R), and robust central tendency methods (trimmed mean, winsorized mean, Huber M-estimator) are verified via R comparison scripts in the repository.

Docker Profiles (Optional R Validation)

StatGuard does not require R for normal usage. The default container is lightweight and focused on PHP development. For scientific auditing, you can enable the r-validation profile to run the R comparison script.

Performance Benchmarks (StatGuard vs MathPHP vs R)

Up to 5x faster than MathPHP in median calculations.

20x faster than MathPHP in robust mean estimation.

Dataset: 100,000 random floats. Benchmarks executed in the Docker performance profile using docker compose --profile performance run --rm benchmark report. R timings use system.time() and only measure computation (file load excluded).

Use json only when you need the shield data output (it does not update the markdown tables).

Scientific Parity (vs R)

Status shows ✅ when the absolute difference between StatGuard and R is below 0.0001.

Generate or refresh the table with php tests/BenchmarkStatGuard.php report.

Method StatGuard ms StatGuard value MathPHP ms MathPHP value R ms R value Status
Median 15.23 499.249 71.69 499.249 1.00 499.249
Quantile Type 1 (p=0.75) 14.79 747.736 14.69 747.7385 1.00 747.736
Quantile Type 2 (p=0.75) 14.36 747.741 15.37 747.7385 1.00 747.741
Quantile Type 3 (p=0.75) 14.81 747.736 15.99 747.7385 2.00 747.736
Quantile Type 4 (p=0.75) 14.75 747.736 15.02 747.7385 1.00 747.736
Quantile Type 5 (p=0.75) 13.99 747.741 14.72 747.7385 1.00 747.741
Quantile Type 6 (p=0.75) 13.67 747.7435 14.42 747.7385 1.00 747.7435
Quantile Type 7 (p=0.75) 14.03 747.7385 15.12 747.7385 1.00 747.7385
Quantile Type 8 (p=0.75) 13.75 747.741833 15.03 747.7385 2.00 747.7418
Quantile Type 9 (p=0.75) 14.10 747.741625 15.15 747.7385 2.00 747.7416
Huber mean 33.00 499.174389 37.83 499.243589 8.00 499.18
Metric (100k) StatGuard ms MathPHP ms R ms Ratio (PHP/R)
Median 15.8 76.5 2.00 7.92
Quantile Type 7 (p=0.75) 16.2 16.0 2.00 8.09
Huber mean 34.8 788.7 10.00 3.48

Precision check (Huber): $\Delta = 0.0056111266$ for $n = 100000$ (warning threshold $10^{-10}$). Smaller datasets showed higher deltas, which are reported by the benchmark warnings.

Consistent results with R core within 0.01% tolerance on the benchmark scale (0-1000).

Tests and Quality

Validated with PHPUnit for full coverage of calculations and data validation.

License

This project is licensed under the MIT License. See LICENSE for details.

Built with ❤️ by cjuol.


All versions of statguard with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cjuol/statguard contains the following files

Loading the files please wait ...