Fit gamma mixture to fertility schedule in R

末鹿安然 提交于 2019-12-03 17:18:22

The reason why it won't run is because you have zeroes in your data set. Here is what you could do:

aa <- a$value[a$value > 0]

Now you can fit the gamma mixture

require(mixtools)
g3 <- gammamixEM(aa)

Now check that it looks OK by plotting the fitted mixture density.

d3 <- function(x) g3$lambda[1]*dgamma(x, g3$gamma.pars[1], 1/g3$gamma.pars[2]) + g3$lambda[2]*dgamma(x, g3$gamma.pars[3], 1/g3$gamma.pars[4])

Here is another pitfall: gammamixEM apparently parametrises the gamma distribution differently to R. Why? Who knows?

x <- seq(min(aa), max(aa), 0.001)
plot(x, d3(x), "l")
hist(aa, col="pink", add=T, freq=F, breaks=10)

Looks reasonable, if far from perfect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!