plotting parametric terms (with partial residuals) from GAM models

1,275 views
Skip to first unread message

Rosemary Hartman

unread,
Jan 9, 2013, 12:14:06 PM1/9/13
to davi...@googlegroups.com
Hello all,

Has anyone tried to plot the terms from a GAM model with the partial residuals on the plot? The plot.gam function from the mgcv package does it quite well, but only for the non-parametric terms. It then passes any parametric terms of the model to the "termplot" function which refuses to put the residuals from a gam model on the plot.

I also tried putting just the parametric terms into the termplot function by itself, but when I asked it to give me the residuals it said:

Error in match.arg(type) :
  'arg' should be one of “deviance”, “pearson”, “scaled.pearson”, “working”, “response”

I have attached my data and code, if anyone can assist I would be eternally grateful.

--
Rosemary Hartman
UC Davis Graduate Group in Ecology
Dr. Sharon Lawler's Lab
roseh...@gmail.com
301-538-0136
gam plotting problems.R
fishlakes.csv

Noam Ross

unread,
Jan 9, 2013, 12:43:52 PM1/9/13
to Davis R Users Group

Hi Rosie,

The trouble seems to be that mgcv does not have a method for calculating partial residuals. That is, residuals.gam() won't take the argument type="partial". residuals.glm DOES have this method, though, and from my quick scan of the functions it should give you correct values. So, before running termplot, do this:

tmp.resid.gam <- residuals.gam

residuals.gam <- residuals.glm

Who knows what other functions this might break, so after you plot be sure to restore it with

residuals.gam <- tmp.resid.gam

Be sure to sanity check the values on your plot.

Noam



--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group, send email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages