Handle RasterBrick objects in risk_unit()
risk_unit(r, eu)
computes the average risk at epidemiological unit taking a Raster as input and a vector map of epi-units.
If r is a RasterBrick
, risk_unit()
currently uses the first layer.
For uncertainty quantification, it would be useful to return a matrix instead of a vector, with as many columns as layers.
For type consistency, it would be better to return always a matrix, even in the case of single-column.
library(mapMCDA)
library(raster, quietly = TRUE)
packageVersion("mapMCDA")
#> [1] '0.4.52'
r <- raster(xmn=-110, xmx=-90, ymn=40, ymx=60, nrow = 10, ncol = 10)
r <- setValues(r, seq.int(ncell(r)))
## polygons covering the region by squares of 2x2 pixels
r0 <- r
res(r0) <- 2*res(r)
epiunits <- as(r0, "SpatialPolygons")
risk_unit(r, epiunits)
#> [1] 6.5 8.5 10.5 12.5 14.5 26.5 28.5 30.5 32.5 34.5 46.5 48.5 50.5 52.5 54.5
#> [16] 66.5 68.5 70.5 72.5 74.5 86.5 88.5 90.5 92.5 94.5
risk_unit(brick(r, 2*r, 3*r), epiunits)
#> [1] 6.5 8.5 10.5 12.5 14.5 26.5 28.5 30.5 32.5 34.5 46.5 48.5 50.5 52.5 54.5
#> [16] 66.5 68.5 70.5 72.5 74.5 86.5 88.5 90.5 92.5 94.5
Created on 2020-09-25 by the reprex package (v0.3.0)