我写了这个程序来为你做数学。只需输入摘要统计信息即可。无需提供数组:
总体比例的一样本Z检验:
要针对平均值而不是比例进行此操作,请相应地更改z的公式
编辑:
这是链接的内容:
import scipy.stats as stats
import math
def one_sample_ztest_pop_proportion(tail, p, pbar, n, alpha):
sigma = math.sqrt((p*(1-p))/(n))
z = round((pbar - p) / sigma, 2)
if tail == 'lower':
pval = round(stats.norm(p, sigma).cdf(pbar),4)
print("Results for a lower tailed z-test: ")
elif tail == 'upper':
pval = round(1 - stats.norm(p, sigma).cdf(pbar),4)
print("Results for an upper tailed z-test: ")
elif tail == 'two':
pval = round(stats.norm(p, sigma).cdf(pbar)*2,4)
print("Results for a two tailed z-test: ")
print("Test statistic = {}".format(z))
print("P-value = {}".format(pval))
print("Confidence = {}".format(alpha))
if pval <= alpha:
print("{} <= {}. Reject the null hypothesis.".format(pval, alpha))
else:
print("{} > {}. Do not reject the null hypothesis.".format(pval, alpha))