Fit gamma mixture to fertility schedule in R

拟墨画扇 提交于 2019-12-05 03:00:06

问题


I am trying to fit a gamma mixture model (two gamma distributions) to an age-fertility profile. I have a dataset containing age specific fertility rates and age, and I want to fit two gammas in order to find the corresponding parameters (in the end I will use fertility profiles from different years and try to see how the parameters evolve over time). I have so far tried to use mixtools library (gammamixEM) but without success. I would be very grateful for some help.

Ale

a<- structure(list(EDAD = structure(1:45, .Label = c("11", "12", "13", "14", "15",   
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", 
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", 
"44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "Total" ),
class = "factor"), value = c(0, 0, 0, 0, 0.002761668, 0.006712018, 0.010820244, 
0.017867778, 0.029533765, 0.034055242, 0.036665669, 0.043840421, 0.042949584, 
0.042344612, 0.050588917, 0.050187588, 0.054114728, 0.057258792, 0.059280324, 
0.062566731, 0.062369629, 0.062154767, 0.063734337, 0.058236776, 0.052623842, 
0.046330921, 0.040639027, 0.033707865, 0.02531141, 0.017651534, 0.010953808, 
0.007463863, 0.003224766, 0.002190101, 0.001117443, 0.000465116, 0.000363901, 
0.00012647, 0.000267326, 0.000280308, 0, 0, 0, 0, 0)), .Names = c("EDAD", "value"), 
class = "data.frame", row.names = 79596:79640)

回答1:


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.



来源:https://stackoverflow.com/questions/17450591/fit-gamma-mixture-to-fertility-schedule-in-r

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