![](/img/trans.png)
[英]Zero-inflated two-part models in GLMMadaptive (R): anova on fixed effects zero-part?
[英]Is there a difference between gamma hurdle (two-part) models and zero-inflated gamma models?
我有半連續的數據(許多精確的零和連續的正結果),我正在嘗試 model。 我從 Zuur 和 Ieno 的 R 中的零膨脹模型初學者指南中很大程度上了解了具有大量零質量的建模數據,該指南區分了零膨脹伽馬模型和他們所謂的“零改變”伽馬模型,他們描述了這種模型作為障礙模型,它結合了零點的二項式分量和正連續結果的伽馬分量。 我一直在探索在glmmTMB
package 中使用ziGamma
選項,並將得到的系數與我按照 Zuur 的書(第 128-129 頁)中的說明構建的障礙 model 進行比較,但它們並不重合。 我很難理解為什么不這樣做,因為我知道伽瑪分布不能取零值,所以我想每個零膨脹伽瑪 model 在技術上都是一個障礙 model。 誰能為我照亮這個? 查看代碼下方有關模型的更多評論。
library(tidyverse)
library(boot)
library(glmmTMB)
library(parameters)
### DATA
id <- rep(1:75000)
age <- sample(18:88, 75000, replace = TRUE)
gender <- sample(0:1, 75000, replace = TRUE)
cost <- c(rep(0, 30000), rgamma(n = 37500, shape = 5000, rate = 1),
sample(1:1000000, 7500, replace = TRUE))
disease <- sample(0:1, 75000, replace = TRUE)
time <- sample(30:3287, 75000, replace = TRUE)
df <- data.frame(cbind(id, disease, age, gender, cost, time))
# create binary variable for non-zero costs
df <- df %>% mutate(cost_binary = ifelse(cost > 0, 1, 0))
### HURDLE MODEL (MY VERSION)
# gamma component
hurdle_gamma <- glm(cost ~ disease + gender + age + offset(log(time)),
data = subset(df, cost > 0),
family = Gamma(link = "log"))
model_parameters(hurdle_gamma, exponentiate = T)
# binomial component
hurdle_binomial <- glm(cost_binary ~ disease + gender + age + time,
data = df, family = "binomial")
model_parameters(hurdle_binomial, exponentiate = T)
# predicted probability of use
df$prob_use <- predict(hurdle_binomial, type = "response")
# predicted mean cost for people with any cost
df_bin <- subset(df, cost_binary == 1)
df_bin$cost_gamma <- predict(hurdle_gamma, type = "response")
# combine data frames
df2 <- left_join(df, select(df_bin, c(id, cost_gamma)), by = "id")
# replace NA with 0
df2$cost_gamma <- ifelse(is.na(df2$cost_gamma), 0, df2$cost_gamma)
# calculate predicted cost for everyone
df2 <- df2 %>% mutate(cost_pred = prob_use * cost_gamma)
# mean predicted cost
mean(df2$cost_pred)
### glmmTMB with ziGamma
zigamma_model <- glmmTMB(cost ~ disease + gender + age + offset(log(time)),
family = ziGamma(link = "log"),
ziformula = ~ disease + gender + age + time,
data = df)
model_parameters(zigamma_model, exponentiate = T)
df <- df %>% predict(zigamma_model, new data = df, type = "response") # doesn't work
# "no applicable method for "predict" applied to an object of class "data.frame"
我的障礙 model 的 gamma 分量的系數和 zigamma model 的固定效應分量是相同的,但 SE 不同,這在我的實際數據中對我感興趣的預測變量的重要性有重大影響。 零膨脹 model 上的系數不同,我還注意到二項式分量中的 z 值與我的二項式 model 中的 z 值相反。 我認為這與我的二項式 model 建模存在概率(1 是成功)和 glmmTMB 可能建模不存在概率(0 是成功)有關?
總之,誰能指出我在 glmmTMB ziGamma model 上做錯了什么?
glmmTMB
package 可以做到這一點:
glmmTMB(formula, family=ziGamma(link="log"), ziformula=~1, data= ...)
應該這樣做。 也許VGAM
中也有一些東西?
要回答有關系數和標准誤的問題:
broom.mixed::tidy
,round(1-abs(tidy(hurdle_g,component="zi")$statistic)/
abs(tidy(hurdle_binomial)$statistic),3)
## [1] 0.057 0.001 0.000 0.000 0.295
截距6%,年齡影響高達30%...
cost>0
)組件的標准誤差幾乎是兩倍的差異,這讓我很困惑; 如果我們簡單地在 glmmTMB 與 glm 中實現 Gamma/log-link,它就成立了。 很難知道如何檢查哪個是正確的/這個案例的黃金標准應該是什么。 在這種情況下,我可能不信任 Wald p 值,而是嘗試使用似然比檢驗來獲取 p 值(通過drop1
)。在這種情況下,model 嚴重錯誤指定(即成本是均勻分布的,與 Gamma 完全不同); 我想知道這是否會使事情變得更難/更糟?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.