Thank you very much for the help Robert!
Works wonders.
-Such a simple addition to the loop to fix the naming of layers :).
This raster package is so brilliant.
atb, Kristin
--
View this message in context:
http://r-sig-geo.2731867.n2.nabble.com/Predict-gam-in-a-loop-on-multiple-raster-stack
Kristin, I think you can do something like this:
lst <- list()
for(i in 1:96) {
Predictors <- stack(stackchl[[i]], stacksst[[i]], stackpar[[i]], lat, lon)
names(Predictos) <- c('chl', 'sst', 'par', 'lat', 'lon')
lst[[i]] <- predict(Predictors, gammodel, na.rm=TRUE, type="response")
}
s <-
I have a gam model with predictor names (variables) par, chl, sst, lat and
lon. The model I called "gammodel".
Then I have predictors for 96 day period in raster stacks: "stackpar",
"stackchl", "stacksst"
-that is 3 different raster stacks - each one with 96 layers.
lat and lon are fixed in time