Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
First we need to define some utility functions for generating the predicted values from a model object:
# Given a model, predict zvar from xvar and yvar# Defaults to range of x and y variables, and a 16x16 gridpredictgrid<-function(model,xvar,yvar,zvar,res=16,type=NULL){# Find the range of the predictor variable. This works for lm and glm# and some others, but may require customization for others.xrange<-range(model$model[[xvar]])yrange<-range(model$model[[yvar]])newdata<-expand.grid(x=seq(xrange[1],xrange[2],length.out=res