I am new to Data Science. Recently I was studying a course about statistics. One of the tasks there was to check the central limit theorem in practice.
The idea was quite simple: take a continuous random variable; generate, say, 1000 samples from it, each of size
n; draw a histogram of the samples. Then find the parameters of the normal distribution using the central limit theorem and draw the PDF of the distribution. As a result, the histogram and the PDF should be, roughly speaking, "similar" (and become more "similar" as
I chose Pareto distribution and, with this Python code,
import numpy as np import matplotlib.pyplot as plt import scipy.stats as sts from math import sqrt n = 10 b = 3.0 random_value = sts.pareto(b) mean = random_value.mean() variance = random_value.var() plt.hist(samples(random_value, n, 1000), bins=20, normed=True) x = np.linspace(0, 6, 100) pdf = sts.norm(mean, sqrt(variance / n)).pdf(x) plt.plot(x, pdf, color='r', label='theoretical PDF')
samples function was like this
def samples(random_value, sample_size, number_of_samples): result = np.asarray() for i in range(number_of_samples): result = np.append(result, np.mean(random_value.rvs(sample_size))) return result
The result looked suspicious to me: there was no expected similarity. I checked the same code with another continuous distribution (with a uniform distribution), and the graphs looked much more similar.
Is it a feature of the Pareto distribution which makes it a bad choice to demonstrate how the central limit theorem works? Or something is wrong with the code itself (e.g., the parameters of the normal distribution are calculated in a wrong way)? Thank you in advance.