使用来自fitdistrplus的fitdist和具有不同大小的Betabinomial分布

时间:2018-11-28 20:04:34

标签: r

一个相关的问题是"using fitdist from fitdistplus with binomial distribution "__main__.Editor是一个接受单变量数据并开始猜测参数的函数。为了拟合二项式和贝塔二项式的数据,虽然是单变量的,但也需要大小。如果每个数据的大小都是固定的,则上述链接具有所需的固定。但是,如果大小不同并且需要传递矢量,则我不确定如何获得正常运行的呼叫。

以下代码中的

fitdistrplus::fitdist是上述链接文章中提供的解决方案-也就是说,集群大小是已知的并且是固定的。对于opt_one,我错误地指定了opt_one(本质上是使N = 125的每个元素),并且这足够接近并且代码可以运行。但是,fix.arg=list(size=125)中的群集大小实际上有所不同。我尝试在N中指定它,并得到一个错误。任何想法都将不胜感激。

opt_two

哪个给:

library(fitdistrplus)
library(VGAM)
set.seed(123)

N <- 100 + rbinom(1000,25,0.9)

Y <- rbetabinom.ab(rep(1,length(N)), N, 1, 2)

head(cbind(Y,N))

opt_one <-
  fitdist(data=Y,
          distr=pbetabinom.ab,
          fix.arg=list(size=125),
          start=list(shape1=1,shape2=1)
  )
opt_one

不错,因为> head(cbind(Y,N)) Y N [1,] 67 123 [2,] 14 121 [3,] 15 123 [4,] 42 121 [5,] 86 120 [6,] 28 125 > opt_one <- + fitdist(data=Y, + distr=pbetabinom.ab, + fix.arg=list(size=125), + start=list(shape1=1,shape2=1) + ) Warning messages: 1: In fitdist(data = Y, distr = pbetabinom.ab, fix.arg = list(size = 125), : The dbetabinom.ab function should return a zero-length vector when input has length zero 2: In fitdist(data = Y, distr = pbetabinom.ab, fix.arg = list(size = 125), : The pbetabinom.ab function should return a zero-length vector when input has length zero > opt_one Fitting of the distribution ' betabinom.ab ' by maximum likelihood Parameters: estimate Std. Error shape1 0.9694054 0.04132912 shape2 2.1337839 0.10108720 Fixed parameters: value size 125 shape1参数分别是1和2(如我们创建shape2时所指定)。这是选项2:

Y

哪个出错:

opt_two <-
  fitdist(data=Y,
          distr=pbetabinom.ab,
          fix.arg=list(size=N),
          start=list(shape1=1,shape2=1)
  )

首次发布后的尝试(感谢Dean Follmann)

我知道我可以编写自己的贝比系数可能性(> opt_two <- + fitdist(data=Y, + distr=pbetabinom.ab, + fix.arg=list(size=N), + start=list(shape1=1,shape2=1) + ) Error in checkparamlist(arg_startfix$start.arg, arg_startfix$fix.arg, : 'fix.arg' must specify names which are arguments to 'distr'. ,如下所示),但是我真的很想使用具有opt_three对象的工具,即拥有{{ 1}}。

fitdist

哪个给:

opt_two

也与Ben Bolker's answer using mle2相关。 fitdist解决方案仍然很大。

1 个答案:

答案 0 :(得分:0)

请查看?fitdistrplus::fitdist()帮助页面的示例4:

# (4) defining your own distribution functions, here for the Gumbel distribution
# for other distributions, see the CRAN task view 
# dedicated to probability distributions
#

dgumbel <- function(x, a, b) 1/b*exp((a-x)/b)*exp(-exp((a-x)/b))
pgumbel <- function(q, a, b) exp(-exp((a-q)/b))
qgumbel <- function(p, a, b) a-b*log(-log(p))

fitgumbel <- fitdist(serving, "gumbel", start=list(a=10, b=10))
summary(fitgumbel)
plot(fitgumbel)

然后-因为您实际上是RTM -受到启发和了解-用自己指定的N创建自己的[dpq]函数:

dbbspecifiedsize <- function(x, a, b) dbetabinom.ab(x, size=N, shape1=a, shape2=b)
pbbspecifiedsize <- function(q, a, b) pbetabinom.ab(q, size=N, shape1=a, shape2=b)
qbbspecifiedsize <- function(p, a, b) qbetabinom.ab(p, size=N, shape1=a, shape2=b)

opt_four <-
  fitdist(data=Y,
          distr="bbspecifiedsize",
          start=list(a=1,b=1)
  )
opt_four

给出:

> opt_four
Fitting of the distribution ' bbspecifiedsize ' by maximum likelihood 
Parameters:
   estimate Std. Error
a 0.9526875 0.04058396
b 2.0261339 0.09576709

opt_three的估算值非常相似,并且是fitdist的对象。

相关问题