【问题标题】:"Python" implementing hypothesis testing“Python”实现假设检验
【发布时间】:2019-09-26 00:33:50
【问题描述】:

如果我有一个长期稳定的平均值 = 45 和标准 = 11 和一个大小为 80 的样本,平均值 = 43 如何使用 python 对 0.05 和 0.1 显着性水平进行测试

假设检验是推论统计中用于确定总体参数值的关键工具。

【问题讨论】:

    标签: python


    【解决方案1】:

    您需要使用学生的 t 检验,但在我们开始之前,您必须计算样本的标准误差。

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

    # 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, p
    

    【讨论】:

      猜你喜欢
      • 2021-12-31
      • 2021-07-13
      • 2016-07-20
      • 2017-10-27
      • 2020-06-30
      • 2020-09-02
      • 2019-06-26
      • 2021-06-23
      • 2015-01-21
      相关资源
      最近更新 更多