比例测试:Z检验与自举/置换-不同的结果

时间:2019-03-01 17:11:44

标签: statistics probability hypothesis-test

我正在学习假设检验,并通过以下示例进行操作:

一家大型电力公司的首席执行官声称,他的1,000,000名客户中有80%对他们所获得的服务非常满意。为了检验这一说法,当地报纸使用简单的随机抽样调查了100位客户。在抽样客户中,有73%的客户表示非常满意。基于这些发现,我们是否可以拒绝首席执行官80%的客户非常满意的假设?使用0.05的显着性水平。

与使用Python中的引导方法相比,使用单样本z检验计算p值时得到的结果不同。

Z测试方法:

σ= sqrt [(0.8 * 0.2)/ 100] = sqrt(0.0016)= 0.04 z =(p-P)/σ=(.73-.80)/0.04 = -1.75

双尾检验,所以P(z <-1.75)= 0.04,P(z> 1.75)= 0.04。

因此, P值= 0.04 + 0.04 = 0.08。

引导程序方法(在Python中):

一般方法是从满足80%的人口(1,000,000)中随机抽取100个大小的样本

repeat 5000 times:
    take random sample of size 100 from population (1,000,000, 80% of which are satisfied)
    count the number of satisfied customers in sample, and append count to list satisfied_counts
calculate number of times that a value of 73 or more extreme (<73) occurs. Divide this by the number of items in satisfied_counts

Since it's a two-tailed test, double the result to get the p-value.

使用此方法, p值0.11。

代码如下:

population = np.array(['satisfied']*800000+['not satisfied']*200000)     # 80% satisfied (1M population)
num_runs = 5000
sample_size = 100
satisfied_counts = []

for i in range(num_runs):
    sample = np.random.choice(population, size=sample_size, replace = False)
    hist = pd.Series(sample).value_counts()
    satisfied_counts.append(hist['satisfied'])

p_val = sum(i <= 73 for i in satisfied_counts) / len(satisfied_counts) * 2

两个结果为何不同?任何帮助/指向正确方向均表示赞赏!

1 个答案:

答案 0 :(得分:1)

区别是栅栏/舍入错误的一种形式。

正态近似表示,得到0.73的几率大约是相应的正态分布在0.725和0.735之间的几率。因此,您应该使用0.735作为截止值。这样会使两个数字更接近。