[R] How to extract partial predictions, package mgcv

Staffan Roos staffan.roos at bto.org
Mon Sep 14 20:30:01 CEST 2009


Dear package mgcv users,



I am using package mgcv to describe presence of a migratory bird species as 
a function of several variables, including year, day number (i.e. 
day-of-the-year), duration of survey, latitude and longitude. Thus, the 
"global model" is:



global_model<-gam(present ~ as.factor(year) + s(dayno, k=5) + s(duration, 
k=5) + s(x, k=5) + s(y, k=5), family = binomial(link = logit), data = 
presence, gamma =1.4)



The model works fine, suggesting that all the variables have strong, 
non-linear, influences on the probability of detecting the species. My main 
interest is in the effect "dayno" has on presence, given the inclusion of 
the other explanatory variables. Thus, I would like to extract the values of 
the partial prediction of "dayno" and its associated 2 standard errors above 
and below the main effect, as shown by the code "plot(global_model)".



I have tried to extract the values by using 
"fitted.values(global_model,dayno)", but when plotted, the figure doesn't 
look like the partial prediction for "dayno". Instead, it gives me a very 
scattered figure ("shotgun effect").



Has anyone tried to extract the partial predictions? If so, please could you 
advise me how to do this?



Thanks,



Staffan



P.S.. For comparison, please have a look at Simon Woods paper in R News, 
1(2):20-25, June 2001, especially the figures showing the partial 
predictions of Mackerel egg densities. Using those graphs as an example, I 
would like to extract the partial predictions for e.g. "s(b.depth)", given 
the inclusion of the other variables.

--
Staffan Roos, PhD
Research Ecologist
BTO Scotland




More information about the R-help mailing list