首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用python实现统计假设测试?

如何使用python实现统计假设测试?
EN

Stack Overflow用户
提问于 2019-09-26 00:33:50
回答 1查看 148关注 0票数 0

如果长期稳定平均值为45,标准差为11,样本大小为80,平均值为43,如何用python对0.05和0.1水平的显着性进行检验?

我在做统计假设检验

假设检验是推断统计中确定总体参数的值的一个重要工具。

EN

回答 1

Stack Overflow用户

发布于 2019-09-26 00:40:49

你需要使用学生的t测试,但在我们达到这个目的之前,你必须为你的样本计算标准误差。

这是计算标准错误的代码。std1std2表示每个样本的标准差,您已经有了。

代码语言:javascript
复制
# calculate standard errors
# calculate standard errors
n1, n2 = len(data1), len(data2)
se1, se2 = std1/sqrt(n1), std2/sqrt(n2)

一旦计算了站立错误,就可以使用以下代码计算t测试的结果:

代码语言:javascript
复制
# 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, p
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58108098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档