[R-sig-Geo] Construct prediction grid that has a value for each corresponding predictor raster grid cell

Robert J. Hijmans r.hijmans at gmail.com
Thu Sep 11 18:06:29 CEST 2014


Justin,

See  ?raster::predict

Robert

On Wed, Sep 10, 2014 at 7:42 AM, Justin Michell <jwm302 at gmail.com> wrote:
> I have aligned raster layers as follows:
>
>> NDVI1
> class       : RasterLayer
> dimensions  : 1287, 1321, 1700127  (nrow, ncol, ncell)
> resolution  : 0.008333333, 0.008333333  (x, y)
> extent      : 29.425, 40.43333, -11.725, -1  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names       : layer.1.1.1
> values      : -0.1524615, 0.9153615  (min, max)
>
>> rain1
> class       : RasterLayer
> dimensions  : 1287, 1321, 1700127  (nrow, ncol, ncell)
> resolution  : 0.008333333, 0.008333333  (x, y)
> extent      : 29.425, 40.43333, -11.725, -1  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names       : layer.1.1.1
> values      : 7, 391  (min, max)
>
>
> I have used spBayes::spGLM to get spatial estimates for a logit model (based on predictors including NDVI and rainfall).
>
> I now wish to construct a prediction grid so that I can produce a continuous map of my predicted response based on draws from the predictive posterior distribution (using output from spBayes::spPredict).
>
> What is the best strategy? Should I extend the range of prediction grid to be rectangular (and then recreate raster layers not cropped to my country of interest so that the grid has complete data). Perhaps by using raster::drawExtent() I can ‘draw’ a rectangle over my domain and use those bounds as input for prediction grid.
>
> I was initially thinking of just creating a grid at the same 1x1km resolution as climate layers like so:
>
> grid <- raster(nrows=nrow(NDVI1), ncols=ncol(NDVI1),
>             xmn=bbox(NDVI1)[1], xmx=bbox(NDVI1)[3],
>             ymn=bbox(NDVI1)[2], ymx=bbox(NDVI1)[4])
>
>
> Thanks and Regards
> Justin Michell
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list