Message-ID: <1306389840441-6405741.post@n2.nabble.com>
Date: 2011-05-26T06:04:00Z
From: Robert J. Hijmans
Subject: multivariate output with predict() on rasterStack
In-Reply-To: <70FC67C4A585D1489E66225A4E0238BAF4EFBF@RZS-EXC-CL06.rz-sued.bayern.de>
> 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.