[R-sig-ME] including dispersion parameter in predictions

Alessandra Bielli b|e|||@@|e@@@ndr@ @end|ng |rom gm@||@com
Sat Feb 6 01:25:19 CET 2021


Dear list,

I am fitting this model to predict the dependent variable at the population
mode:

m1.dczig <- glmmTMB(Res.dia.pers ~ Tipo + (1|ID) , data=all, zi=~ Tipo ,
dispformula=~ Tipo , family=ziGamma(link ="log"))

where Res.dia.pers is a continuous variable >= zero, and Tipo is a
categorical variable.

Is it possible to include the dispersion parameter when doing predictions?
I was using this code to predict at the population mode using a model
WITHOUT dispformula:

newdata0 = with(all,
                        expand.grid(
                            Tipo = c("1","2","3","4")))
X.cond = model.matrix(lme4::nobars(formula(m1.dczig)[-2]), newdata0)
beta.cond = fixef(m1.dczig)$cond
pred.cond = X.cond %*% beta.cond
ziformula = m1.dczig$modelInfo$allForm$ziformula
X.zi = model.matrix(lme4::nobars(ziformula), newdata0)
beta.zi = fixef(m1.dczig)$zi
pred.zi = X.zi %*% beta.zi

pred.ucount = exp(pred.cond)*(1-plogis(pred.zi))

set.seed(101)
pred.condpar.psim = mvrnorm(1000,mu=beta.cond,Sigma=vcov(m1.dczig)$cond)
pred.cond.psim = X.cond %*% t(pred.condpar.psim)
pred.zipar.psim = mvrnorm(1000,mu=beta.zi,Sigma=vcov(m1.dczig)$zi)
pred.zi.psim = X.zi %*% t(pred.zipar.psim)
pred.ucount.psim = exp(pred.cond.psim)*(1-plogis(pred.zi.psim))
ci.ucount = t(apply(pred.ucount.psim,1,quantile,c(0.025,0.975)))
ci.ucount = data.frame(ci.ucount)
names(ci.ucount) = c("ucount.low","ucount.high")
pred.ucount = data.frame(newdata0, pred.ucount, ci.ucount)

To include the dispersion parameter, I adapt it by adding

dispformula = m1.dczig$modelInfo$allForm$dispformula
X.disp = model.matrix(lme4::nobars(dispformula), newdata0)
beta.disp = fixef(m1.dczig)$disp
pred.disp = X.disp %*% beta.disp

pred.disppar.psim = mvrnorm(1000,mu=beta.disp,Sigma=vcov(m1.dczig)$disp)
pred.disp.psim = X.disp %*% t(pred.disppar.psim)

How do I include the dispersion parameter in the pred.ucount =
exp(pred.cond)*(1-plogis(pred.zi)) and pred.ucount.psim =
exp(pred.cond.psim)*(1-plogis(pred.zi.psim))? I have found some info here
<https://journal.r-project.org/archive/2017/RJ-2017-066/RJ-2017-066.pdf>,
equations 1 to 5, but I am not sure how to use this info for my case.

Thanks for your help,
Alessandra

PS: I am not using the predict function because I want to calculate CIs as
well.

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list