[R-sig-Geo] multivariate output with predict() on rasterStack

Robert Hijmans r.hijmans at gmail.com
Thu May 26 08:04:00 CEST 2011


> 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.



More information about the R-sig-Geo mailing list