Skip to content

Tutorials

Short recipes for common tasks.

1) Detect outlier bias

use Cjuol\StatGuard\StatsComparator;

$data = [10, 12, 11, 15, 10, 1000];

$comparator = new StatsComparator();
$analysis = $comparator->analyze($data);

echo $analysis['verdict'];

Quick interpretation: - If the verdict warns about bias, use median or Huber. - If the verdict is stable, the classic mean is safe.

2) Robust summary for reports

use Cjuol\StatGuard\RobustStats;

$data = [10, 12, 11, 15, 10, 1000];

$robust = new RobustStats();
$summary = $robust->getSummary($data);

file_put_contents('summary.csv', $robust->toCsv($data));
file_put_contents('summary.json', $robust->toJson($data));

3) R-compatible quantiles

use Cjuol\StatGuard\QuantileEngine;

$data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$engine = new QuantileEngine();

// Type 7 is the R default.
$q7 = $engine->quantile($data, 0.75, 7);

// Type 1 is more discrete and depends on ordering.
$q1 = $engine->quantile($data, 0.75, 1);

When to pick type 7: - General exploratory analysis. - Consistency with R defaults.

When to pick type 1: - Discrete series or counts where you do not want interpolation.