【发布时间】:2015-06-05 09:00:34
【问题描述】:
我正在尝试估计 tweedie(或复合 Poisson-gamma)分布的有限混合。我搜索了我能想到的所有资源,但没有找到任何关于如何做到这一点的资源。
我目前正在尝试使用 R 中的 flexmix 包编写不同的 M-step 驱动程序,如第 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")
retval@defineComponent <- 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)
})
retval@fit <- 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(retval@defineComponent))
}
retval
}
但是,这会导致以下错误:
dtweedie(y, xi = p, mu = mu, phi = phi) 中的错误: 不相容数组的二元运算
有没有人做过或见过 tweedie 分布的有限混合?您能否指出我使用 flexmix 或其他方式完成此任务的正确方向?
【问题讨论】:
-
您找到解决方案了吗?
标签: r poisson mixture-model gamma-distribution tweedie