#*
#* predict function for glmm.admb - not compatible with other packages
#* First, confirm this method is giving good results by using old data and comparing to $fitted values
#* Inputs:
#* model = fitted glmm.admb model object
#* newdata = new dataset to use in fitting (or test with old data)
#* islog = was there an implicit or explicit log-link function used by glmm.admb? (optional, default=TRUE)
#*
predict <- function(model, newdata, islog=TRUE)
{
# Construct model matrix, nobs x np
MM <- model.matrix(model$fixed, data=newdata, contrasts.arg=NULL)
beta <- as.vector(model$b)
phat <- MM %*% beta
if (islog==TRUE) phat <- exp(phat)
return (phat);
}
- Predict using old data for comparison
- Compare with fitted values returned from GLMM.admb and original data
- Note: implicit log-link function
phat <- as.vector(model$fitted);
fvec <- predict(model=TopModels[[1]], newdata=A2, log=TRUE)
pobs <- as.vector(newdata$N_Species)
- Compare against observed and fitted results
library("ggplot2")
qplot(x=pobs, y=phat, geom="point") + xlab("Observed") + ylab("Predicted (fitted)")
qplot(x=pobs, y=fvec) + xlab("Observed") + ylab("Fixed-only predictions")
qplot(x=phat, y=fvec) + xlab("Predicted (fitted)") + ylab("Fixed-only predictions")