【问题标题】:Fit points with gamma CDF in python or R在 python 或 R 中使用 gamma CDF 拟合点
【发布时间】:2016-11-22 13:33:06
【问题描述】:

我有一系列看起来像这样的情节:

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 的帖子,但我不明白。

【问题讨论】:

  • fitdistr(a, "gamma") 来自MASS-package in R 似乎有效,对吧?

标签: python r cdf gamma-distribution


【解决方案1】:
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]))

【讨论】:

    【解决方案2】:

    使用包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)
    

    【讨论】:

      猜你喜欢
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 2011-01-17
      • 2019-06-04
      • 2020-07-10
      相关资源
      最近更新 更多