R中的qgeom和Python中的scipy.stats.geom.ppf有什么区别?

What is the difference between qgeom in R and scipy.stats.geom.ppf in Python?

我的理解是两种方式都应该给出低尾概率对应的分位数。但是,我得到不同的结果。 例如:- qgeom(0.99,0.5) 在 R 中给出 6,而 geom.ppf(0.99,0.5) 在 Python.

中给出 7

tldr; R 和 SciPy.

中几何分布的 pmf 不同
  1. 首先,最好确认在 R 和 Python 中计算的一般分位数是一致的,例如在正态分布的情况下

    from scipy.stats import norm
    norm.ppf(0.99)
    #2.3263478740408408
    
    qnorm(0.99)
    #[1] 2.326348
    
  2. 对于几何分布的情况,分位数函数不同是因为概率质量函数(pmf)不同。在R中,几何分布的pmf定义为p(1 - p)^k(参见help("Geometric"));在 Python 的 SciPy 模块中,几何分布定义为 p(1 - p)^(k-1)(参见 scipy.stats.geom)。

    您可以在 Wikipedia article 中找到这两个定义的关键数量摘要。本质上,^k 定义是 "used for modeling the number of failures until the first success",而 ^(k-1) 定义与 "the probability that the kth trial (out of k trials) is the first success" 有关。

    另请参阅:Which geometric distribution to use?