博客
关于我
Python Pingouin:搞定各种假设检验和统计模型 !
阅读量:799 次
发布时间:2023-03-06

本文共 2840 字,大约阅读时间需要 9 分钟。

假设检验的基本步骤与实际应用

假设检验是统计学中的一个核心概念,广泛应用于科学研究和数据分析。以下将详细阐述假设检验的基本步骤,并结合实际案例进行探讨。

1. 假设检验的基本步骤

假设检验的核心在于通过数据验证某个假设的真实性。检验过程通常包括以下几个关键步骤:

  • 提出研究假设:假设检验始于提出一个可以通过统计测试验证的陈述。例如,在药物研究中,假设可以是“药物X比安慰剂更能降低血压”。此时需要明确零假设和备择假设:

    • 零假设(Null Hypothesis,NH):在总体中不存在显著差异,各组间的变量均衡。
    • 备择假设(Alternative Hypothesis,AH):总体中存在显著差异。
  • 数据收集:根据研究目标采集相应数据。常见方法包括实验、调查、采访等。例如,A/B测试通过收集不同网站版本用户反馈评估性能。

  • 选择检验方法:根据变量类型和分布选择合适的检验方法。常见方法包括t检验、方差分析(ANOVA)、卡方检验、克鲁斯卡尔-沃利斯检验(Kruskal-Wallis)等。

  • 指定显著性水平(α):设定拒绝零假设的阈值,通常为0.05。检验结果通过p值与α比较得出结论,p值越小表示结果越显著。

  • 执行假设检验并解释结果:通过计算统计量(如F值、t值、卡方值等)并与临界值比较,确定是否拒绝零假设。若统计量值大于临界值,则拒绝零假设;反之则不拒绝。

  • 2. Pingouin库:强大又友好的统计工具

    在实际应用中,选择合适的工具至关重要。Pingouin库(https://pingouin-stats.org/index.html)是一个开源的Python库,提供了多种统计检验功能,包括ANOVA、t检验、卡方检验、克鲁斯卡尔-沃利斯检验等。此外,它还支持相关分析和线性回归模型的建立。

    3. 种子数据集:案例研究

    本文基于UCI机器学习库提供的种子数据集(https://archive.ics.uci.edu/ml/datasets/seeds),探讨小麦品种之间的几何差异。数据集包含三种小麦品种(Kama、Rosa和Canadian)的 样本信息,包括面积、周长、紧密度等变量。

    我们的研究假设是“小麦品种间的紧密度均值不同”。具体检验步骤如下:

  • 数据预处理:使用pandas的groupby函数按品种分组,计算各变量的均值。结果显示,除了紧密度外,其他变量均值值显著不同。

  • 可视化分析:通过pandas的boxplot函数绘制箱线图,直观比较各品种的紧密度分布。

  • 正态性测试:使用Pingouin的normality函数进行Shapiro-Wilk正态性检验,评估数据是否符合正态分布。通过KDE图形进一步验证。

  • 方差齐性检验:应用Levene测试评估组间方差是否相等。若方差不齐,则采用Welch ANOVA进行检验。

  • ANOVA结果分析:Welch ANOVA结果显示,各品种间的紧密度均值存在显著差异。进一步通过Games-Howell事后测试确定具体差异。

  • 4. 结论

    通过本次案例研究,我们验证了假设检验在实际数据分析中的重要性。Pingouin库通过提供详细的统计结果,使得假设检验过程更加高效和直观。

    代码和完整案例分析可在GitHub上下载:https://github.com/derevirn/hypothesis-test

    参考文献

  • Biau, D. J., Jolles, B. M., & Porcher, R. (2010). P-value and the theory of hypothesis testing: An explanation for new researchers. Clinical Orthopaedics and Related Research.
  • Lenhard, J. (2020). Models and statistical inference: The controversy between Fisher and Neyman–Pearson. The British Journal for the Philosophy of Science.
  • Vallat, R. (2018). Pingouin: statistics in Python. Journal of Open Source Software.
  • Charytanowicz, M., et al. (2010). Complete gradient clustering algorithm for features analysis of x-ray images. Information Technologies in Biomedicine.
  • Scheffe, H. (1999). The analysis of variance. John Wiley & Sons.
  • Shapiro, S. S., & Wilk, M. B. (1965). An analysis of variance test for normality (complete samples). Biometrika.
  • Schmider, E., et al. (2010). Is it really robust? Reinvestigating the robustness of ANOVA against violations of the normal distribution assumption. Methodology: European Journal of Research Methods for the Behavioral and Social Sciences.
  • Levene, H. (1961). Robust tests for equality of variances. Contributions to Probability and Statistics: Essays in Honor of Harold Hotelling.
  • Liu, H. (2015). Comparing Welch ANOVA, a Kruskal-Wallis test, and traditional ANOVA in case of heterogeneity of variance. Journal of Educational Statistics.
  • Games, P. A., & Howell, J. F. (1976). Pairwise multiple comparison procedures with unequal n's and/or variances: A Monte Carlo study. Journal of Educational Statistics.
  • 转载地址:http://pmafk.baihongyu.com/

    你可能感兴趣的文章
    pyhton验证码识别
    查看>>
    PyInstaller 中的 Kivy Garden - 试图跟踪导入
    查看>>
    Pyinstaller 和 PyQt5 macOS Mojave 兼容性问题
    查看>>
    pyinstaller 打包资源文件
    查看>>
    PyInstaller 构建的 Windows EXE 因多处理而失败
    查看>>
    Pyinstaller--Windowed或--noconsole.exe不允许打开chromedriver
    查看>>
    Pyinstaller依赖项的许可证
    查看>>
    PyInstaller可执行文件找不到包含的flASK-COMPRESS
    查看>>
    Pyinstaller:‘;Fiona‘;没有属性‘;_loading‘;(很可能是由于循环导入)
    查看>>
    pyinstaller:更改应用程序图标
    查看>>
    Pylint“未解决的导入“;Visual Studio 代码中的错误
    查看>>
    pyLoad远程代码执行漏洞复现(CVE-2023-0297)
    查看>>
    pymongo update_one(),upsert=True,不使用$运算符
    查看>>
    pymongo 中的快速或批量更新
    查看>>
    PyQ5学习笔记——使用内部槽函数关闭窗口
    查看>>
    PyQ5学习笔记——使用自定义槽函数关闭窗口
    查看>>
    PyQt MimeData 文件名
    查看>>
    PyQt QString转成python stirng
    查看>>
    PyQt QToolButton在焦点时不更新图标
    查看>>
    PyQt 正确使用 emit() 和 pyqtSignal()
    查看>>