我正在尝试从《统计入门》 3E的6.3.1节中的陪审团问题进行模拟,但是我的模拟似乎并不正确。请参见下面。
我的仿真代码:
white_proba = 0.72
black_proba = 0.07
hispanic_proba = 0.12
other_proba = 0.09
sample = 275
_sum = 275
n = 4
array_of_proba = np.array([white_proba, black_proba, hispanic_proba, other_proba])
number_of_simulations = 1000
master_list_of_chi_stat = []
master_list_of_chi_p_value = []
for b in range(number_of_simulations):
observed_values = np.random.multinomial(_sum, np.ones(n)/n, size=1)[0]
expected_values = array_of_proba * sample
chi_square_stats = np.sum(np.square((observed_values - expected_values)/np.sqrt(expected_values)))
master_list_of_chi_stat.append(chi_square_stats)
我的图形代码:
# Add histogram data
x2 = master_list_of_chi_stat
# Group data together
hist_data = [x2]
group_labels = ['Chi_Square_Stat']
# Create distplot with custom bin_size
fig = ff.create_distplot(hist_data, group_labels, bin_size=0.1)
# Plot!
py.iplot(fig, filename='Chi_Square_Stat')
很显然,我的代码出了点问题。预先谢谢你。