R understanding raster's corLocal neighborhood size parameter

455 views Asked by At

I am calculating the Pearson correlation between two rasters (identical in dimensions and cell size) in a moving window with the corLocal from the raster package. It is not clear (to me) from the manual what the neighborhood size parameter (ngb) actually means. E.g., does a ngb = 5 mean that the correlation is calculated for the focal cell plus the top-bottom-right-left cells?

I looked at the code and corLocal calls getValuesFocal():

getValuesFocal(x, 1, nrow(x), ngb=ngb)

but I couldn't understand what getValuesFocal actually does.

Thanks, Ilik

1

There are 1 answers

0
Tim Assal On BEST ANSWER

The ngb parameter defines the neighborhood size. For example, I believe ngb=5 defines a 5 x 5 neighborhood. This should be equivalent to ngb=c(5,5) which is a vector of two integers defining the numbers of rows and cols in the neighborhood or focal window. In this example, an individual cell in the output raster would represent the correlation calculated from a 5 x 5 cell neighborhood in the two input rasters.

The raster library documentation on p. 118 might help too.