| Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2026-07-06 (26 days ago)  | | Not yet rated by the users | | Total: Not yet counted | | Not yet ranked |
|
| Description | | Author |
This package can simulate the central limit theorem.
It provides a class that can take as parameters the number of samples and the sample size and generates an array of mean values and statistic values of the generated distribution with values of mean, standard deviation, minimum, and maximum value.
The package also provides a page that can show retrieve the generated values from the PHP script that runs on the server side and display the values on a canvas page element using the Chart.js JavaScript library. Innovation Award
 July 2026
Nominee
Vote |
The central limit theorem can be used to make predictions of values that make up part of samples that follow a normal distribution.
This package can generate mean statistic values following the central limit theorem and the generated values on a chart.
Manuel Lemos |
| |
 |
|
Innovation award
 Nominee: 25x
Winner: 5x |
|
Instructions
Example
<?php
require 'src/CLTSimulator.php';
use Alexsoft\Statistics\CLT\CLTSimulator;
$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";
?>
|
Details
Central 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.
| |
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.