Hi all,
I am new to using R-INLA and I'm trying to understand how to use the inla.make.lincombs() function to obtain the mean and 95% credible intervals for different levels of a covariate. In this case, my response is catch-per-effort and I have 2 categorical covariates, gear (2 levels; EF and DT) and habitat (3 levels; Trib, MC, and SC) in my model. For simplicity, I'll focus only on positive catches here without random effects or a spatial component, but this will be part of a barrier hurdle model. Here is what I've done so far.
# create the gamma response
SVC2$pos <- ifelse(SVC2$CPUE_Ped_Hr > 0, SVC2$CPUE_Ped_Hr, NA)
# create the model matrix
Xm <- model.matrix(~ fGear + fHabitat, data = SVC2)
X <- data.frame(fGearDT = Xm[, 2],
fHabitatMC = Xm[, 3],
fHabitatSC = Xm[, 4])
# create the stack
stack.gamma1 <- inla.stack(tag = 'GammaFit1',
data = list(pos = SVC2$pos),
A = list(1, 1),
effects = list(Intercept = rep(1, nrow(SVC2)),
X = as.data.frame(X)))
# and the formula
fglm1 <- formula(pos ~ -1 + Intercept + fGearDT + fHabitatMC + fHabitatSC)
#use inla.make.lincombs() to specify the contrast of interest
lcb <- inla.make.lincombs("Intercept" = -1, 'fGearDT' = 1,
"fHabitatMC" = 0, "fHabitatSC" = 0)
#run the model
glm1 <- inla(fglm1,
family = 'gamma',
lincomb = lcb,
data = inla.stack.data(stack.gamma1),
control.compute = list(dic = T,
waic = T),
control.predictor = list(A = inla.stack.A(stack.gamma1),
link = 1))
summary(glm1)
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
Intercept 4.277
0.123 4.041 4.275
4.526 4.270 0
fGearDT 0.863
0.140 0.587 0.864
1.138 0.864 0
fHabitatMC -0.289 0.151
-0.583 -0.289 0.010 -0.291 0
fHabitatSC -0.313 0.213
-0.717 -0.318 0.121 -0.328 0
The summary indicates an important gear effect, but no effect of habitat on catch-per-effort.
What I'm uncertain of is the appropriate way to obtain the mean catch-per-effort and credible intervals for each gear (EF and DT). It appears that I can use
glm1$marginals.fixed$Intercept
to get the posterior distribution of the Intercept (i.e., gear = EF and habitat = Trib) and
glm1$marginals.fixed$fGearDT
to get the posterior for the difference between DT and EF in Trib habitat.
Am I understanding that correctly? If so, is there a way to separate the gear effects from the Trib habitat? Is there another way to derive the mean and 95% credible intervals for visualizing differences in catch-per-effort by gear?
As I move forward with this, I would also like to examine if there are spatial changes in the posterior distributions by adding the random effect of site or the SPDE into the linear combinations. How might I go about doing that?
I greatly appreciate any advice/suggestions/corrections to my understanding of this issue.
Thank you,
Ben