๐ฏ Simulating the Law of Large Numbers with R
This project demonstrates the Law of Large Numbers using the standard normal distribution in R.
I simulate random values and check what proportion of them fall between -1 and 1. According to the 68โ95โ99.7 rule, about 68.2% of values in a standard normal distribution should fall within this interval.
- Generates
Nrandom values from the standard normal distribution - Counts how many values lie between
-1and1 - Calculates the proportion and compares it to the theoretical 68.2%
- Visualizes the distribution using:
- Density plot with shaded region between -1 and 1
- Histogram with highlighted range
- Bar plot comparing theoretical and simulated values
This is a practical demonstration of how the Law of Large Numbers works:
The larger the sample size, the closer the result gets to the expected theoretical value.
It's also a great way to practice working with:
- Loops and conditionals in R
- Basic data visualization
- Statistical thinking using simulation
You can expect an output like:
Simulated Proportion: 0.6823
Which closely matches the theoretical value of 0.682.
You can run the script using any R environment (e.g., RStudio). Feel free to modify the value of N to see how results vary with smaller or larger sample sizes.
๐ฉโ๐ป Author
Samira Sadeghi Data Science student in Milan ๐ฎ๐น Researcher in Machine Learning & Cancer Detection ๐ฌ Passionate about R, Python, and building insight from data
โธป
โญ๏ธ If you like this project
Give it a โญ๏ธ on GitHub

