Hello, According to the help file, the predict() function in the raster package creates a RasterLayer. Since a RasterLayer cannot store more than one layer like a RasterStack, I wonder if it is possible to use the predict() functions when the output of the prediction is multivariate? For example when predicting the class probabilities. Is it possible to create a RasterStack with the predict function, in which the probabilies for different classes are stored in single layers? Thank you. TIM ---------------- 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
multivariate output with predict() on rasterStack
2 messages · Häring, Tim (LWF), Robert J. Hijmans
According to the help file, the predict() function in the raster package
creates a RasterLayer. Since a
RasterLayer cannot store more than one layer like a RasterStack, I wonder if it is possible to use the predict() functions when the output of the prediction is multivariate? For example when predicting the class probabilities. Is it possible to create a RasterStack with the predict function, in which the probabilies for different classes are stored in single layers?
Tim,
You can create a RasterBrick. You need to use the index argument to indicate
how many layers, and which, (columns in the prediction matrix) you expect /
want.
For example:
x <- predict(stack, model, type='prob', index=1:2)
Unfortunately that does not work in the current version, because the '...'
arguments ('type' in this case) are ignored. (I introduced an error solving
a problem for you 2 weeks ago. 1 step forward, 2 steps back). I'll upload a
new version to CRAN tomorrow.
But there is a work around, using the fun argument. You will also need this
argument if your modelling method does not return a matrix but, e.g., a
list.
predfun <- function(model, data) {
predict(model, data=data, type='prob')
}
x <- predict(stack, model, fun=predfun, index=1:2)
Robert
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/multivariate-output-with-predict-on-rasterStack-tp6403349p6405741.html
Sent from the R-sig-geo mailing list archive at Nabble.com.