Adding random variables

Foundations of Probability in Python

Alexander A. Ramírez M.

CEO @ Synergy Vision

The central limit theorem (CLT)

The sum of random variables tends to a normal distribution as the number of them grows to infinity.

Conditions:

  • The variables must have the same distribution.
  • The variables must be independent.
Foundations of Probability in Python

Sample generation animation for poisson distribution

Foundations of Probability in Python

Random selection from a sample plot

Foundations of Probability in Python

Sample random selection from the population

Foundations of Probability in Python

Sample mean from sample calculation and histogram

Foundations of Probability in Python

Poisson population plot

# Add the imports
from scipy.stats import poisson, describe
from matplotlib import pyplot as plt
import numpy as np
# Generate the population
population = poisson.rvs(mu=2, size=1000, random_state=20)
# Draw the histogram with labels
plt.hist(population, bins=range(9), width=0.8)
plt.show()
Foundations of Probability in Python

Poisson population histogram

Foundations of Probability in Python

Sample means plot

# Generate 350 sample means, selecting
# from population values
np.random.seed(42)

# Define list of sample means
sample_means = []
for _ in range(350):
    # Select 10 from population
    sample = np.random.choice(population, 10)
    # Calculate sample mean of sample
    sample_means.append(describe(sample).mean)
Foundations of Probability in Python

Sample means plot (Cont.)

$$ $$

# Draw histogram with labels
plt.xlabel("Sample mean values")
plt.ylabel("Frequency")
plt.title("Sample means histogram")
plt.hist(sample_means)
plt.show()

Sample mean histrogram with Bell shape

Foundations of Probability in Python

Let's add random variables

Foundations of Probability in Python

Preparing Video For Download...