DownloadCentral Limit Theorem (CLT) - PHP Simulator
The Central Limit Theorem (CLT) is one of the most fundamental principles in statistics.
In simple terms: when we take many sample means from random samples, the distribution of those means tends to become normal (a bell curve), regardless of the shape of the original population.
This small project implements a CLT Simulator in PHP using a simple example:
dice rolls ? sample means ? distribution of means.
Project Goals
-
Demonstrate how the CLT works in practice.
-
Simulate thousands of samples.
-
Compute basic statistics (mean, standard deviation, min, max).
-
Verify that sample means converge to the theoretical value 3.5 (the expected value of a fair die).
Structure
/public
index.html
/src
CLTSimulator.php
composer.json
example.php
README-EL.md
README.md
web-demo.php
How the CLT works here
-
Each die roll produces a value between 1-6 (uniform distribution).
-
We roll N dice ? compute the sample mean.
-
We repeat this process numSamples times.
-
The sample means form a bell-shaped curve centered around 3.5.
-
The larger the sample size, the more ?normal? the distribution becomes.
Usage Example
require 'src/CLTSimulator.php';
$sim = new CLTSimulator();
$numSamples = 10000; // Number of samples
$sampleSize = 30; // Size of each sample
$means = $sim->simulate($numSamples, $sampleSize);
$stats = $sim->statistics($means);
echo "Central Limit Theorem Simulation\n";
echo "Samples: $numSamples | Sample Size: $sampleSize\n\n";
echo "Mean of all sample means: {$stats['mean']} (theoretical = 3.5)\n";
echo "Standard deviation: {$stats['std_dev']}\n";
echo "Range: {$stats['min']} - {$stats['max']}\n";
Expected Results
With sampleSize = 30 and numSamples = 10000:
-
The mean should be close to 3.5
-
The standard deviation should be small
-
The range should converge around 2.5-4.5
-
The distribution of sample means should resemble a normal distribution
License
MIT License.
What does the CLT ultimately show?
That sample means are far more predictable than individual data points.
Even a chaotic dataset becomes symmetric and orderly when viewed through the lens of averages. |