Skip to content
Prev 21586 / 29559 Next

How do I calculate neighborhood contiguity in R?

On Tue, 26 Aug 2014, Shanley Thompson wrote:

            
Please note that "crash" means that R error-exits. I believe you mean that 
R ran out of memory, and it does this in different ways on different 
platforms. You didn't provide the output of sessionInfo(), so we don't 
know your platform. Obviously a neighbour object with almost 640 million 
observations, say with <=8 neighbours each, is itself a very large object. 
But this isn't the main problem.
Step back and ask yourself whether the entities represented by 30x30m 
raster cells are actually entities (like botanical field plots) or are an 
artificial result of the arbitrary gridding of the scene by the 
instrument. I would argue that a:

RRRGG
RRGGG
RGGBB
GGBBB
GBBBB

grid is three entities, not 25, with the R G and B entities gridded 
inflating the degrees of freedom - and giving completely different sets of 
join counts. The only reason to believe the 30x30 grid is if the scale or 
footprint of the land cover classes (or whatever) that you are studying 
matches the grid resolution.

So the simple answer is: don't do join count on this kind of data unless 
the entities are suitable - even if there was a way (making the counts as 
a focal procedure in raster perhaps), the results would be spurious. You 
could also sample your scene in say 500x500 blocks, choosing a random SW 
cell to start. With a number of samples, you'd get a picture of the join 
counts that would not be far from the whole scene.

Hope this helps,

Roger