admin管理员组文章数量:1356884
I'm treating a data with one continuous variable and one categorical variable. I built a model as following using glmmTMB:
m=glmmTMB(y~x+(1+x|group), family=Gamma(link="log"), data=dat)
'group' is the categorical variable with 20 levels and I want to calculate the confidence interval for each group considering both fixed and random slope. Now I have two questions:
- Is it plausible to calculate CIs for each group in a model with random slope?
- If it's okay, how can I implement that?
So far I tried confint() but both seemed something is wrong.
confint(m, method="profile")
2.5 % 97.5 %
(Intercept) 3.47032911 3.62824116
x 0.03020511 0.06036813
theta_1+x|group.1 -1.85226484 -1.30972404
theta_1+x|group.2 -3.74515169 -3.04747076
theta_1+x|group.3 -0.14530387 0.83050143
Although group is the variable with 20 levels, only 3 is showed here and their names are dropped.And I also tried parametric bootstrapping with chatGPT's help.
for(i in 1:nboot){
sim_data <- simulate(m)[[1]]
dat_boot <- m$frame
dat_boot$y <- sim_data
m_boot <- try(glmmTMB(y ~ x + (1+x|group),
family=Gamma(link="log"), data=dat_boot), silent=TRUE)
if(!inherits(m_boot, "try-error")){
fix_boot <- fixef(m_boot)$cond["x"]
ranef_boot <- ranef(m_boot)$cond$plot[,"x"]
boot_slopes[i, ] <- fix_boot + ranef_boot
}
}
ci <- apply(boot_slopes, 2, function(x){
quantile(x, probs = c(0.025, 0.975), na.rm=TRUE)
})
print(ci)
I checked the result but I highly suspect something is wrong, especially the grouping structure is lost because the CIs are too homogenic/similar among groups(seeing my row data, I believe they shouldn't).
I don't cling to glmmTMB, but fitting is somehow better with this than lme4.
I'm treating a data with one continuous variable and one categorical variable. I built a model as following using glmmTMB:
m=glmmTMB(y~x+(1+x|group), family=Gamma(link="log"), data=dat)
'group' is the categorical variable with 20 levels and I want to calculate the confidence interval for each group considering both fixed and random slope. Now I have two questions:
- Is it plausible to calculate CIs for each group in a model with random slope?
- If it's okay, how can I implement that?
So far I tried confint() but both seemed something is wrong.
confint(m, method="profile")
2.5 % 97.5 %
(Intercept) 3.47032911 3.62824116
x 0.03020511 0.06036813
theta_1+x|group.1 -1.85226484 -1.30972404
theta_1+x|group.2 -3.74515169 -3.04747076
theta_1+x|group.3 -0.14530387 0.83050143
Although group is the variable with 20 levels, only 3 is showed here and their names are dropped.And I also tried parametric bootstrapping with chatGPT's help.
for(i in 1:nboot){
sim_data <- simulate(m)[[1]]
dat_boot <- m$frame
dat_boot$y <- sim_data
m_boot <- try(glmmTMB(y ~ x + (1+x|group),
family=Gamma(link="log"), data=dat_boot), silent=TRUE)
if(!inherits(m_boot, "try-error")){
fix_boot <- fixef(m_boot)$cond["x"]
ranef_boot <- ranef(m_boot)$cond$plot[,"x"]
boot_slopes[i, ] <- fix_boot + ranef_boot
}
}
ci <- apply(boot_slopes, 2, function(x){
quantile(x, probs = c(0.025, 0.975), na.rm=TRUE)
})
print(ci)
I checked the result but I highly suspect something is wrong, especially the grouping structure is lost because the CIs are too homogenic/similar among groups(seeing my row data, I believe they shouldn't).
I don't cling to glmmTMB, but fitting is somehow better with this than lme4.
Share Improve this question asked Mar 28 at 11:40 Y.Y.Y.Y. 31 bronze badge 5 |1 Answer
Reset to default 1There is both a statistical question and a computational question here.
The statistical question is "can I get confidence intervals on expressions involving a random effect?" The answer is, "it depends whether you're a frequentist or not, and how rigorous you want to be". According to a frequentist, random effects are not parameters, so they (and expressions involving them) don't have confidence intervals. However, we can get prediction intervals, or intervals combining the sampling distribution of the parameters with the conditional distributions of the random effects ...
There is an implementation for lme4
here and for glmmTMB
here (I realize this violates the "link-only answer" rule, I will try to come back later and copy the content here ...)
本文标签: rConfidence intervals for each grouping factor in glmmTMB modelStack Overflow
版权声明:本文标题:r - Confidence intervals for each grouping factor in glmmTMB model - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744039518a2580403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
group
as a fixed effect rather than random. – PBulls Commented Mar 28 at 11:53x
— ifx
is continuous, this doesn’t make much sense. – zephryl Commented Mar 28 at 13:20