statsmodels.stats.proportion.test_proportions_2indep

statsmodels.stats.proportion.test_proportions_2indep(count1, nobs1, count2, nobs2, value=None, method=None, compare='diff', alternative='two-sided', correction=True, return_results=True)[source]

比较两个独立比例的假设检验

这假设我们有两个独立的二项分布样本。

零假设和备择假设是

对于 compare = ‘diff’

  • H0: prop1 - prop2 - value = 0

  • H1: prop1 - prop2 - value != 0 如果 alternative = ‘two-sided’

  • H1: prop1 - prop2 - value > 0 如果 alternative = ‘larger’

  • H1: prop1 - prop2 - 值 < 0 如果 alternative = ‘smaller’

对于 compare = ‘ratio’

  • H0: prop1 / prop2 - value = 0

  • H1: prop1 / prop2 - value != 0 如果 alternative = ‘two-sided’

  • H1: prop1 / prop2 - 值 > 0 如果 alternative = ‘larger’

  • H1: prop1 / prop2 - 值 < 0 如果 alternative = ‘smaller’

对于 compare = ‘odds-ratio’

  • H0: 或 - 值 = 0

  • H1: 或 - 值 != 0 如果 alternative = ‘two-sided’

  • H1: 或 - 值 > 0 如果 alternative = ‘larger’

  • H1: 或 - 值 < 0 如果 alternative = ‘smaller’

其中 优势比 or = prop1 / (1 - prop1) / (prop2 / (1 - prop2))

Parameters:
count1int

第一个样本的计数。

nobs1int

第一个样本的样本量。

count2int

第二个样本的计数。

nobs2int

第二个样本的样本大小。

valuefloat

在零假设下,两个独立比例的差异值、风险比或比值比。默认情况下,比例相等,差异为0,风险比和比值比为1。

methodstr

计算假设检验的方法。如果方法为None,则使用默认方法。默认方法可能会随着更多方法的添加而改变。

差异:

  • ‘wald’,

  • ‘阿格斯蒂-卡福’

  • ‘score’ if correction is True, then this uses the degrees of freedom

    修正 nobs / (nobs - 1) 如 Miettinen Nurminen 1985 所述

比率:

  • ‘log’: 使用对数变换的wald检验

  • ‘log-adjusted’: wald test using log transformation,

    将计数加0.5

  • ‘score’: if correction is True, then this uses the degrees of freedom

    修正 nobs / (nobs - 1) 如 Miettinen Nurminen 1985 所述

比值比:

  • ‘logit’: 使用logit变换的wald检验

  • ‘logit-adjusted’: wald test using logit transformation,

    将计数加0.5

  • ‘logit-smoothed’: wald test using logit transformation, biases

    单元格通过总共添加两个观察值来计算独立性。

  • ‘score’ if correction is True, then this uses the degrees of freedom

    修正 nobs / (nobs - 1) 如 Miettinen Nurminen 1985 所述

compare{‘diff’, ‘ratio’ ‘odds-ratio’}

如果 compare 是 diff,那么假设检验是针对风险差 diff = p1 - p2。 如果 compare 是 ratio,那么假设检验是针对由 ratio = p1 / p2 定义的风险比。 如果 compare 是 odds-ratio,那么假设检验是针对由 or = p1 / (1 - p1) / (p2 / (1 - p2) 定义的比值比。

alternative{‘two-sided’, ‘smaller’, ‘larger’}

备择假设,可以是双侧的或单侧检验中的任意一个。

correctionbool

如果 correction 为 True(默认),则使用 Miettinen 和 Nurminen 的小样本方差修正 nobs / (nobs - 1)。仅在 method=’score’ 时适用。

return_resultsbool

如果为真,则返回一个包含额外信息的结果实例,否则返回一个包含统计量和p值的元组。

Returns:
resultsresults instance or tuple

如果 return_results 为 True,则返回一个包含属性中信息的 results 实例。 如果 return_results 为 False,则仅返回 statisticpvalue

statisticfloat

检验统计量渐近正态分布 N(0, 1)

pvaluefloat

基于正态分布的p值

other attributes :

关于假设检验的附加信息

注释

Status: experimental, API and defaults might still change.

更多 methods 将被添加。

当前的默认方法是

  • ‘diff’: ‘agresti-caffo’,

  • ‘ratio’: ‘对数调整’,

  • ‘odds-ratio’: ‘logit-adjusted’


Last update: Oct 16, 2024