[R-sig-Geo] problem with predict() in raster with GAM

Häring, Tim (LWF) Tim.Haering at lwf.bayern.de
Wed May 11 16:09:56 CEST 2011


Dear List,

I want to use the predict() function from the raster-package to apply a GAM to my gridded predictors. Unfortunately I get an error message:

When using a linear model everything works fine:
> mod.lm <- lm(y ~ Slope + Boen_By50m + Hoehe_abs, data=dat_nwt)
> p <- predict(object = r, model = mod.lm, filename='gebiet_1/sturmwurf.img', 
  progress='text', na.rm = FALSE, overwrite = TRUE, format = 'HFA', type='response')
  |======================================================================| 100%

The same, when using a GLM
> mod.glm <- glm(y ~ Slope + Boen_By50m + Hoehe_abs, data=dat_nwt, family=binomial())
> p <- predict(object = r, model = mod.glm, filename='gebiet_1/sturmwurf.img', 
  progress='text', na.rm = FALSE, overwrite = TRUE, format = 'HFA', type='response')
  |======================================================================| 100%

But, when using a GAM I get an Error.
> mod.gam <- gam(y ~ Slope + Boen_By50m + Hoehe_abs, data=dat_nwt, family=binomial())
> p <- predict(object = r, model = mod.gam, filename='gebiet_1/sturmwurf.img', 
  progress='text', na.rm = FALSE, overwrite = TRUE, format = 'HFA', type='response')
  |                                                                      |   0%
  Error in object[-omit, , drop = FALSE] : incorrect number of dimensions

Does anybody know what 'incorrect number of dimensions' means in this context?

Thanks
TIM

***
> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)

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

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

other attached packages:
[1] rgdal_0.6-33  raster_1.8-12 sp_0.9-81     mgcv_1.7-6   

loaded via a namespace (and not attached):
[1] grid_2.13.0        lattice_0.19-23    Matrix_0.999375-50 nlme_3.1-100      


---------------- 
Tim Häring
Bavarian State Institute of Forest Research 
Department of Soil and Climate
Hans-Carl-von-Carlowitz-Platz 1
D-85354 Freising

E-Mail: tim.haering at lwf.bayern.de
http://www.lwf.bayern.de



More information about the R-sig-Geo mailing list