PHP code example of touilelhadj / biostat-php
1. Go to this page and download the library: Download touilelhadj/biostat-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
touilelhadj / biostat-php example snippets
TouilElhadj\BiostatPhp\BiostatAnalysis;
$stats = new BiostatAnalysis();
// Two-by-two table: 45 exposed cases, 18 exposed non-cases,
// 30 unexposed cases, 22 unexposed non-cases.
$chi = $stats->chi2Test2x2(45, 18, 30, 22);
echo "chi² = {$chi['chi2']}, p = {$chi['p']}\n";
// chi² = 1.8027, p = 0.1794
$or = $stats->oddsRatio(45, 18, 30, 22);
echo "OR = {$or['or']} [{$or['ci_low']}, {$or['ci_high']}]\n";
// OR = 1.83 [0.84, 3.98]
// Welch's t-test
$t = $stats->tTest(
[10, 12, 11, 13, 14, 12, 11],
[15, 17, 16, 18, 16, 17, 15]
);
echo "t = {$t['t']}, df = {$t['df']}, p = {$t['p']}\n";
// Logistic regression (one continuous covariate)
$y = [0,0,0,1,1,1,1,1,0,1,1,0,1,1,1,0,0,1,1,1];
$x = [1,1,2,2,3,3,4,4,1,2,3,4,5,5,4,2,1,3,4,5];
$lr = $stats->logisticRegression($y, $x);
echo "OR = {$lr['or']}, p = {$lr['p']}\n";
// Benjamini–Hochberg FDR adjustment
$adj = BiostatAnalysis::benjaminiHochberg([0.001, 0.01, 0.04, 0.2, 0.5]);
// [0.005, 0.025, 0.067, 0.25, 0.5]
bash
composer bibtex
@software{touil_biostat_php_2026,
author = {TOUIL, Elhadj},
title = {biostat-php: a pure-PHP biostatistics library for
survey-based epidemiological studies},
year = {2026},
version = {1.0.0},
url = {https://github.com/Touil-Elhadj/biostat-php}
}