[R] problem with predict.gam in package gam

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Sep 15 16:44:02 CEST 2011


On Wed, 2011-09-14 at 18:06 -0500, Drew Tyre wrote:
> I am trying to reproduce plots in Chapter 3 of Zuur et al Mixed
> Effects models and extensions in Ecology. For pedagogical reasons,
> they make a series of plots with gam(...) in package gam. I encounter
> errors that trace back to the predict.gam method. Below is a
> repeatable example using one of the example datasets:

The code works for me with:

> sessionInfo()
R version 2.13.1 Patched (2011-07-08 r56332)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] splines   grid      stats     graphics  grDevices utils
datasets 
[8] methods   base     

other attached packages:
[1] gam_1.04         analogue_0.7-4   princurve_1.1-10 MASS_7.3-13     
[5] lattice_0.19-23  vegan_1.17-12   

loaded via a namespace (and not attached):
[1] tools_2.13.1

G

> library(gam)
> data(kyphosis)
> test = gam(Kyphosis ~ s(Age,4) + Number, family = binomial, data=kyphosis)
> predict(test) # works
> predict(test,se.fit=TRUE) # fails
> #Error in dim(data) <- dim : attempt to set an attribute on NULL
> 
> # after debugging, it wants a model frame ...
> test = gam(Kyphosis ~ s(Age,4) + Number, family = binomial,
> data=kyphosis, model=TRUE)
> predict(test,se.fit=TRUE) # fails, but with a different error
> # Error in terms.default(object, data = data) :
> #   no terms component nor attribute
> 
> I am using R 2.13.1 on a PC inside RStudio.
> 
> I realize I can do this in package mgcv, but just curious as to
> whether this is something known and fixable?
> 
> Thanks
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list