r-spatialecology/landscapemetrics

Does pad_raster introduce bias?

Closed this issue · 4 comments

Sometimes we need to add padding to a raster at the boundary of the landscapes. Following, the "old" row and column Ids 1 become row and column IDs 2 afterwards.

Could this introduce some problems? We always remove the padding I think at some point again (which should result in the original row/col numbers).

However, maybe we need to have a second look at this (but not on a Friday #yolo)

Hi @mhesselbarth, could you add a small example here? It would be easier to discuss the issue then.

> (mat <- matrix(c(1, 3, 3, 2, 1, 
+                 2, 1, 3, 1, 2, 
+                 2, 1, 1, 3, 2, 
+                 3, 3, 2, 1, 1,
+                 2, 1, 1, 3, 3), nrow = 5, ncol = 5))
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    2    3    2
[2,]    3    1    1    3    1
[3,]    3    3    1    2    1
[4,]    2    1    3    1    3
[5,]    1    2    2    1    3
> 
> mat[2, 4] # just picked an example cell
[1] 3
> 
> (mat_padded <- pad_raster(mat)[[1]]) # pad raster
     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] -999 -999 -999 -999 -999 -999 -999
[2,] -999    1    2    2    3    2 -999
[3,] -999    3    1    1    3    1 -999
[4,] -999    3    3    1    2    1 -999
[5,] -999    2    1    3    1    3 -999
[6,] -999    1    2    2    1    3 -999
[7,] -999 -999 -999 -999 -999 -999 -999
> 
> mat_padded[2, 4] # not the same cell anymore
[1] 2
> 
> mat_padded[3, 5] # now mat[2, 4] is acutally here
[1] 3

Here a short example: Because of the padding, the row/col IDs change. The value in the original matrix at mat[2, 4] is in mat_padded[3, 5] after the padding (depending on how many rows/cols are added).

However, I'm not sure if this leads to any problems. I guess everything should be fine because we only look at the neighbourhood structure which doesn't change. But maybe worthwhile checking anyhow.

@mhesselbarth I cannot think right now of any problem that this could create... It is good that you've opened this issue though - maybe someone will find this issue in the future and make a case why it is wrong/ok.

I also thought about it a bit more but couldn't find any problems.

Please re-open if anything comes up.