[R] problem with predict.gam in package gam

Drew Tyre atyre2 at unl.edu
Fri Sep 16 04:18:36 CEST 2011


Thank you!

It also works on a second computer here with the details below, so
something must be messed up on the other machine.

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] gam_1.04.1

loaded via a namespace (and not attached):
[1] blme_0.01-3        grid_2.13.1        lattice_0.19-30    lme4_0.999375-41
[5] Matrix_0.9996875-3 nlme_3.1-101       stats4_2.13.1      tcltk_2.13.1
[9] tools_2.13.1

On Thu, Sep 15, 2011 at 9:44 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> 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
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>



-- 
Drew Tyre

School of Natural Resources
University of Nebraska-Lincoln
416 Hardin Hall, East Campus
3310 Holdrege Street
Lincoln, NE 68583-0974

phone: +1 402 472 4054
fax: +1 402 472 2946
email: atyre2 at unl.edu
http://snr.unl.edu/tyre
http://aminpractice.blogspot.com
http://www.flickr.com/photos/atiretoo



More information about the R-help mailing list