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()