在 python 或 R 中使用伽玛 CDF 拟合点

Fit points with gamma CDF in python or R

我有一系列这样的图:

python代码:

a = np.array([4,4,4,4,5,5,5,6,6,6,6,6,6,6,7,7,7,8,8,8,9])
b = np.array([i/len(a) for i in range(1, len(a)+1)])
pl.plot(a,b, 'ro')

r 代码:

a <- c(4,4,4,4,5,5,5,6,6,6,6,6,6,6,7,7,7,8,8,8,9)
b <- seq(0,1,length = length(a))
plot(a, b, col = "red")

出于某种目的,我需要用伽马分布的最佳累积分布函数 (CDF) 来拟合这些点。有什么办法可以在 python 或 R 中以数字方式做到这一点?我正在使用 winpython 所以我可以非常直接地导入 R 代码。

PS: 我找到了 this post 但我不明白。

使用包 fitdistrplus:

a <- c(4,4,4,4,5,5,5,6,6,6,6,6,6,6,7,7,7,8,8,8,9)
library(fitdistrplus)
fit <- fitdist(a, "gamma", lower = c(0,0))
plot(fit)
library(MASS)
gammafit <- fitdistr(a, "gamma")   
#    shape        rate   
#    17.552961    2.902459 
#    ( 5.366214) ( 0.900112)

显然,伽玛参数 17.55(形状)和 2.90(速率)最适合您的数据。

plot(a, b, col = "red")
lines(a, pgamma(a, gammafit$estimate[1], gammafit$estimate[2]))