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

Justin Michell jwm302 at gmail.com
Fri Sep 26 19:30:05 CEST 2014


Apologies. Robert, I mean. 

On Sep 26, 2014, at 7:27 PM, Justin Michell <jwm302 at gmail.com> wrote:

> Thank you, Roger. I have a grid now and I am in the process of experimenting with different resolutions for prediction, but I am worried that the yearly averaged predictor variables in the grid have some NA values in them. I only cropped my WorldClim data because it was already at the correct resolution:
> 
> # smaller extent and coarser res than original question posted
>> meanTempStack 
> class       : RasterBrick 
> dimensions  : 36, 37, 1332, 12  (nrow, ncol, ncell, nlayers)
> resolution  : 0.1666667, 0.1666667  (x, y)
> extent      : 33.66667, 39.83333, -8.833333, -2.833333  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
> data source : in memory
> names       : meanTemp1, meanTemp2, meanTemp3, meanTemp4, meanTemp5, meanTemp6, meanTemp7, meanTemp8, meanTemp9, meanTemp10, meanTemp11, meanTemp12 
> min values  :       6.3,       7.0,       7.1,       6.2,       5.1,       4.1,       3.2,       3.6,       4.6,        5.7,        6.0,        6.2 
> max values  :      29.2,      29.4,      29.5,      28.4,      27.5,      26.8,      26.1,      25.9,      26.3,       27.1,       28.2,       28.9 
> 
>> class(grid)
> [1] "SpatialPixelsDataFrame"
> attr(,"package")
> [1] “sp"
> 
>> nrow(grid)
> [1] 1332
> 
> sum(as.numeric(is.na(grid$meanTemp)))
> [1] 54
> 
> sum(as.numeric(is.na(grid$NDVI)))
> [1] 27
> 
> Some rows in my raster for all months have an NA value. My climate data comes from WorldClim and MODIS NDVI data. 
> 
> My question is will the fact that not each grid cell is complete affect the prediction? And is there something I can check for along the way before I put raster stacks into a grid to control for NA’s if it is a problem. 
> 
> Thanks 
> Justin
> 
> 
> On Sep 11, 2014, at 6:06 PM, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
> 
>> 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