【问题标题】:AttributeError: module 'statsmodels.sandbox' has no attribute 'stats'AttributeError:模块“statsmodels.sandbox”没有属性“stats”
【发布时间】:2018-04-23 08:42:09
【问题描述】:

Statsmodels 似乎是唯一提供FDR-based BH adjustment for p-values 的python 库(除了rpy2),但它似乎不再包含在内:

statsmodels.sandbox.stats.multicomp.fdrcorrection0()

AttributeError: module 'statsmodels.sandbox' has no attribute 'stats'

此模块是否已从 0.6.1 中删除? Besides using rpy2,还有其他广泛使用的 FDR p 值调整实现吗?

【问题讨论】:

  • 我不认为整个 stats 模块已被删除。您可能需要显式导入它。 (另外fdrcorrection0还在master branch中)

标签: python numpy scipy statsmodels rpy2


【解决方案1】:

相关代码已移出沙箱,现在位于statsmodels.stats.multitest 沙盒函数只是非沙盒函数的别名。在线文档目前有点过时了。

直接导入

>>> from statsmodels.stats.multitest import fdrcorrection
>>> fdrcorrection
<function fdrcorrection at 0x0000000008554B70>

通过 api 使用它

>>> import statsmodels.api as sm
>>> sm.stats.fdrcorrection
<function fdrcorrection at 0x0000000008554B70>

这是当前仍包含别名的旧位置

>>> from statsmodels.sandbox.stats.multicomp import fdrcorrection0
>>> fdrcorrection0
<function fdrcorrection at 0x0000000008554B70>

编辑statsmodels.stats.multitest中的函数列表:

>>> import statsmodels.stats.multitest as multi
>>> dir(multi) # output edited
['NullDistribution', 'fdrcorrection', 'fdrcorrection_twostage', 'local_fdr', 'multipletests']

【讨论】:

    【解决方案2】:

    0.8.0 版仍然存在:

    import statsmodels
    print(statsmodels.__version__)  
    # 0.8.0rc1
    
    from statsmodels.sandbox.stats.multicomp import fdrcorrection0
    print(fdrcorrection0)
    # <function fdrcorrection at 0x0E5A3E88>
    

    您可能没有导入子模块statsmultipcomp

    【讨论】:

    • 直接导入有效。为什么当我 tab-completed statsmodels.sandbox. 我没有在建议的子包列表中看到它?
    • 是的。需要导入模块,以便自省可以看到其内容。
    猜你喜欢
    • 2018-04-14
    • 2019-02-18
    • 1970-01-01
    • 2020-01-01
    • 2019-07-20
    • 2021-11-05
    • 2021-11-04
    • 2021-02-23
    相关资源
    最近更新 更多