1

I am using the following packages:

library(aod)
library(MASS)
library(ggplot2)

I am following the example R code from the following link: http://stats.idre.ucla.edu/r/dae/logit-regression/

Here is the code for my GLMM

str(data1)
flocation <- factor(data1$location)
fID <- factor(data1$ID)
GLMM1 <- glmmPQL(presence ~ water + location + turbidity + temperature + 
sp.cond, random = ~ 1|fID, family = binomial, data = data1)
summary(GLMM1)

I made predictions based on varying location and water levels, while holding temp and turb constant

newdata1 <- with(data1, 
                 data.frame(water = water, 
                            temperature = mean(temperature), 
                            turbidity = mean(turbidity),
                            sp.cond = mean(sp.cond),
                            flocation = flocation))
newdata1$water.levelPred <- predict(GLMM1, type = "response") 
newdata1

To get confidence intervals I used the code below

newdata2 <- cbind(newdata1, predict(GLMM1, newdata = newdata1, type = "link",
                                    se = TRUE))
newdata2 <- within(newdata2, {
  PredictedProb <- plogis(fit)
  LL <- plogis(fit - (1.96 * se.fit))
  UL <- plogis(fit + (1.96 * se.fit))
})

I get the following errors after running the confidence interval code:

Error in predict.lme(object, newdata, level = level, na.action = na.action) : cannot evaluate groups for desired levels on 'newdata'

Error in plogis(fit) : object 'fit' not found

Why would this occur?

Because I can't get past this step I am having problems moving forward to plot the CI with predicted probabilities with the code below:

plot in ggplot2

ggplot(newdata2, aes(x = water, y = water.levelProb)) + geom_ribbon(aes(ymin = LL, ymax = UL, fill = flocation), alpha = 0.2) + geom_line(aes(colour = flocation),size = 1)+facet_wrap(~flocation)+xlab("Water Depth (m)")+ylab("Predicted Probability")+theme_bw()
user153066
  • 11
  • 2
  • The error on the `predict.lme` is due to the absence of `fID` in your `new data`. – Adam Quek Apr 22 '17 at 04:29
  • Thanks! do you by chance know how I would incorporate the R code to account for fID as a random effect? – user153066 Apr 22 '17 at 11:46
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) first. It's hard to explain without knowing what is the problem you are facing in the first place. – Adam Quek Apr 24 '17 at 01:24

0 Answers0