3
我試圖估計Tweedie(或複合Poisson-gamma)分佈的有限混合。我已經搜尋了我能想到的任何資源,但沒有找到任何資源來說明如何做到這一點。Tweedie的有限混合
我目前正在使用flexmix包R寫入不同的M-步進驅動器,如在12-14頁的flexmix小插曲概述。這裏是我的代碼,它依賴於CPLM包:
tweedieClust <- function(formula = .~.,offset = NULL){
require(tweedie)
require(cplm)
require(plyr)
require(dplyr)
retval <- new("FLXMC", weighted = TRUE, formula = formula, dist = "tweedie",
name = "Compound Poisson Clustering")
[email protected] <- expression ({
predict <- function(x, ...) {
pr <- mu
}
logLik <- function(x, y, ...){
dtweedie(y, xi = p, mu = mu, phi = phi) %>%
log
}
new("FLXcomponent",
parameters=list(coef=coef),
logLik=logLik, predict=predict,
df=df)
})
[email protected] <- function (x, y, w, component) {
fit <- cpglm(formula = y ~ x, link = "log", weights=w, offset=offset)
with(list(coef = coef(fit), df = ncol(x),mu = fit$fitted.values,
p = fit$p, phi = fit$phi),
eval([email protected]))
}
retval
}
然而,這會導致以下錯誤:
Error in dtweedie(y, xi = p, mu = mu, phi = phi) : binary operation on non-conformable arrays
有沒有人做過或者看到特威迪分佈的有限混合?你能指出我在正確的方向來完成這個,使用flexmix或其他?
你找到了一個解決方案? – spore234 2015-10-09 08:57:49