Professional Documents
Culture Documents
Central Limit Theorem
Central Limit Theorem
1
2 1000001 P00087842 F 0-17 10 A
3 1000001 P00085442 F 0-17 10 A
4 1000002 P00285442 M 55+ 16 C
5 1000003 P00193542 M 26-35 15 A
6 1000004 P00184942 M 46-50 7 B
7 1000004 P00346142 M 46-50 7 B
8 1000004 P0097242 M 46-50 7 B
9 1000005 P00274942 M 26-35 20 A
2
[9]: def get_means_of_n_samples_with_m_size(data, n, m):
sample_mean_m_samples_n_ele = []
for i in range(0,n):
samples = random.sample(range(0, data.shape[0]), m)
sample_mean_m_samples_n_ele.append(data[samples].mean())
return sample_mean_m_samples_n_ele
axs[i, j].set_title(key)
axs[i, j].legend()
3
[11]: sample_means = dict()
sample_means['1000samples_50ele'] =␣
↪get_means_of_n_samples_with_m_size(data,1000, 50)
sample_means['100samples_100ele'] =␣
↪get_means_of_n_samples_with_m_size(data,100, 100)
sample_means['1000samples_100ele'] =␣
↪get_means_of_n_samples_with_m_size(data,1000, 100)
sample_means['100samples_1000ele'] =␣
↪get_means_of_n_samples_with_m_size(data,100, 1000)
sample_means['1000samples_1000ele'] =␣
↪get_means_of_n_samples_with_m_size(data,1000, 1000)
plt.show()
4
[14]: x = PrettyTable()
x = PrettyTable(["#samples_name", "P_Mean", "Sampel mean", "P_Std", "Sample␣
↪Std", "mu_x"+u"\u2248"+"mu", "std_x"+u"\u2248"+"std/"+u"\u221A"+"n"])
5
for i, key in enumerate(sample_means.keys()):
sample_mean = np.round(np.array(sample_means[key]).mean(), 3)
sample_std = np.round(np.array(sample_means[key]).std(), 3)
population_std_est = np.round(population_std/np.sqrt(sample_sizes[i][1]), 3)
row = []
row.append(key)
row.append(population_mean)
row.append(sample_mean)
row.append(population_std)
row.append(sample_std)
row.append(str(sample_mean)+u"\u2248"+str(population_mean))
row.append(str(sample_std)+u"\u2248"+str(population_std_est))
x.add_row(row)
print(x)
+---------------------+---------+-------------+----------+------------+---------
---------+-----------------+
| #samples_name | P_Mean | Sampel mean | P_Std | Sample Std |
mu_x�mu | std_x�std/√n |
+---------------------+---------+-------------+----------+------------+---------
---------+-----------------+
| 100samples_50ele | 9333.86 | 9293.414 | 4981.017 | 642.308 |
9293.414�9333.86 | 642.308�704.422 |
| 1000samples_50ele | 9333.86 | 9304.882 | 4981.017 | 711.299 |
9304.882�9333.86 | 711.299�704.422 |
| 100samples_100ele | 9333.86 | 9343.436 | 4981.017 | 529.173 |
9343.436�9333.86 | 529.173�498.102 |
| 1000samples_100ele | 9333.86 | 9336.437 | 4981.017 | 508.684 |
9336.437�9333.86 | 508.684�498.102 |
| 100samples_1000ele | 9333.86 | 9334.247 | 4981.017 | 147.713 |
9334.247�9333.86 | 147.713�157.514 |
| 1000samples_1000ele | 9333.86 | 9331.619 | 4981.017 | 158.095 |
9331.619�9333.86 | 158.095�157.514 |
+---------------------+---------+-------------+----------+------------+---------
---------+-----------------+