0

I am modelling the probability of species presence based on environmental variables. My dataset contains both real presence data and pseudo-absence (randomly generated absence) data. My environmental variable include distance to lotic water, distance to lentic water, percent impervious surface, and distance to roads. I have fit the following model.

model <- glmer(presence ~ scale(lotic_distance) + scale(lentic_distance) + 
                          scale(percent_impervious) + scale(road_distance) + (1 | Municipality),
              data = df,
              family = binomial(link = "logit"))

What I want to plot is "what is the probability of occurrence of this species for each variable?" I also want to plot confidence intervals.

I found this post: Confidence intervals for predictions from logistic regression but it only deals with one x variable. Any guidance would be appreciated.

1
  • 4
    Since this is a mixed model with a non-collapsible link, you have to be careful whether you are getting (or want to get) conditional or marginal predictions. See e.g. this post on Cross Validated and especially the links therein. Commented Oct 3 at 7:36

1 Answer 1

4

I'm guessing that you're looking for effects plots, which show the effects of a single variable, using some sensible procedure (it varies across packages) to condition or marginalize across the other variables. (Why one predictor variable at a time? For two predictor variables, it's hard to show the predictions and confidence intervals over ranges of both variables; for more than two, it's practically impossible.)

Under the heading "prediction and estimation", the Mixed Models Task View lists

emmeans, effects, margins, MarginalMediation, marginaleffects, ggeffects.

Here's an example using marginaleffects (on a simpler model than yours, but the same approach should work for your model):

library(marginaleffects)
mod <- lm(mpg ~ hp * wt * am, data = mtcars)
plot_predictions(mod, condition = c("hp", "wt"))

a marginal effects plot showing predicted values and CIs for mpg as a function of hp, for different quintiles of wt

In this case the first condition variable is used for the x-axis and predictions (and CIs) are shown for quintile values of the second. You'd have to make one plot for each variable of interest, specifying condition or by for each one. library(effects); plot(allEffects(mod)) will try to plot all of the effects for a model, but uses a slightly less sophisticated approach to condition on (rather than marginalizing out) the non-focal variables).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.