The formula for global Moran's I is:

where i is an index of analysis units (basically, measurement units of of your map, or in your case pixels in the raster) and j is an index of the neighbors of each map unit. The formula for local Moran's I is extremely similar, except that since local Moran's I is calculated separately for each analysis unit indexed by i, in the top part of the fraction you don't need to sum over i:

Values for
and
will be distributed around the mean, so, intuitively, over the entire study area high and low clusters will offset each other and global Moran's I will be constrained to lie between -1 and 1. But for local Moran's I, a cluster (high, low, doesn't matter) will be comprised of values where
and
deviate significantly from the mean, and therefore the top part of the fraction in the second equation will be large in absolute value, much larger than the global deviation from the mean captured in the bottom part of the fraction by
.
In your constructed example, you can see this clearly. The top rows are low values, the middle rows are near the mean, and the bottom rows are high values. Therefore, as demonstrated in your second plot, local Moran's I is high in the top and bottom rows, because those rows contain values far from the mean. Local Moran's I is near 0 in the middle rows, because those values are all near the mean. Your example does not show dispersion (the classic checkerboard pattern), so local Moran's I is not negative anywhere.
Let's calculate
by hand for one of the pixels. Pixel number 15 has eight neighbors with values 4, 5, 6, 14, 16, 24, 25, 26. So:
x = 1:100
Ii = length(x) *
(15 - mean(x)) *
sum(1 * (c(4, 5, 6, 14, 16, 24, 25, 26) - mean(x))) /
sum((x - mean(x))^2)
Ii
# [1] 12.09961
Incidentally, this does not equal the same value for pixel 15 produced by MoranLocal
:
x1[15]
# 1.512451
At first I thought I did something wrong, so I created a vector 10x10 grid in vector format that was an exact analog of the 10x10 raster and ran it through the localmoran
function in package spdep
. It turns out that MoranLocal
is calculating
using a row-standardized weights matrix, whereas the formula I included above is based on using a simple binary queen's contiguity matrix. spdep
gives you control over these options. Using the row-standardized matrix, the
are 1/8 (eight neighbors at 1/8 each sum to 1), so:
x = 1:100
Ii = length(x) *
(15 - mean(x)) *
sum(0.125 * (c(4, 5, 6, 14, 16, 24, 25, 26) - mean(x))) /
sum((x - mean(x))^2)
Ii
# [1] 1.512451
The original source for local Moran's I is Anselin (1995), "Local Indicators of Spatial Association—LISA" (appears to be open access).