如果长期稳定平均值为45,标准差为11,样本大小为80,平均值为43,如何用python对0.05和0.1水平的显着性进行检验?
我在做统计假设检验
假设检验是推断统计中确定总体参数的值的一个重要工具。
发布于 2019-09-26 00:40:49
你需要使用学生的t测试,但在我们达到这个目的之前,你必须为你的样本计算标准误差。
这是计算标准错误的代码。std1和std2表示每个样本的标准差,您已经有了。
# calculate standard errors
# calculate standard errors
n1, n2 = len(data1), len(data2)
se1, se2 = std1/sqrt(n1), std2/sqrt(n2)一旦计算了站立错误,就可以使用以下代码计算t测试的结果:
# function for calculating the t-test for two independent samples
def independent_ttest(data1, data2, alpha):
# calculate means
mean1, mean2 = mean(data1), mean(data2)
# calculate standard errors
se1, se2 = sem(data1), sem(data2)
# standard error on the difference between the samples
sed = sqrt(se1**2.0 + se2**2.0)
# calculate the t statistic
t_stat = (mean1 - mean2) / sed
# degrees of freedom
df = len(data1) + len(data2) - 2
# calculate the critical value
cv = t.ppf(1.0 - alpha, df)
# calculate the p-value
p = (1.0 - t.cdf(abs(t_stat), df)) * 2.0
# return everything
return t_stat, df, cv, phttps://stackoverflow.com/questions/58108098
复制相似问题