Getting response scale plots for a binomial GAMM #309
-
Hi, I'm currently stuck on how to plot the results of a binomial GAMM on a response scale using gratia. I specified the model with the following code: The goal of this model is to examine the interaction effects of temperature (Temp) and length (Length) on the movement (Move; 0 or 1) of animals under two different conditions (Condition; A and B ). I want to plot the effects of each term on a response scale, ranging from 0 to 1. I've found that the smooth_estimates function can provide estimates of the partial effects, but I'm unsure how to transform these partial effects to the response scale in the case of a binomial GAMM. Does the following code achieve plotting the effects of the interaction term under condition A on a response scale? I initially added the value of intercept to the partial effect of that term to "est" and then converted it to a response scale using the inverse link function of logit.
Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Firstly, you are using an out of date version of gratia; I suggest you update before proceeding. Secondly, your model is incorrectly specified; you are not including the group means for mod <- mgcv::gam(Move ~ Condition + # Condition means
te(Temp, Length, by = Condition) + # tensor product for each level of Condition
s(Time) + # smooth of time
s(ID, bs = "re"), # random subject-level intercepts
family = binomial(link = "logit"),
data = data) I'm not sure it makes a lot of sense to plot these on the response scale and it gets complicated because you will now have the parametric effect for the Because you have to bring in these other effects, the plots aren't really partial effects now, but really are just predictions from the model at some combination of predictors. As such, it might be easier to just generate predictions at the required values and ignore the terms you are not interested in. Assuming you update to the current CRAN version of gratia, this can be done as ds <- data_slice(mod,
Temp = evenly(Temp),
Length = evenly(Temp),
Condition = evenly(Condition))
# note that something will be in `ds` for `Time` and `ID`
# but we will exclude those effects when predicting
fv <- fitted_values(mod, data = ds, exclude = c("s(Time)", "s(ID)")) Now you can plot these using |
Beta Was this translation helpful? Give feedback.
Firstly, you are using an out of date version of gratia; I suggest you update before proceeding.
Secondly, your model is incorrectly specified; you are not including the group means for
Condition
. As you have just two levels forCondition
it is perhaps best to do this through a fixed parametric effect such that your model will become:I'm not sure it makes a lot of sense t…