Moran's I is calculated for each polygon based on the neighbor and weight lists.
Arguments
- x
A numeric vector.
- nb
a neighbor list object for example as created by
st_contiguity()
.- wt
a weights list as created by
st_weights()
.- alternative
default
"two.sided"
. Should be one of"greater"
,"less"
, or"two.sided"
to specify the alternative hypothesis.- nsim
The number of simulations to run.
- ...
See
?spdep::localmoran_perm()
for more options.
Details
local_moran()
calls spdep::localmoran_perm()
and calculates the Moran I for each polygon. As well as provide simulated p-values.
See also
Other stats:
st_lag()
,
st_nb_dists()
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
lisa <- guerry %>%
mutate(nb = st_contiguity(geometry),
wt = st_weights(nb),
moran = local_moran(crime_pers, nb, wt))
# unnest the dataframe column
tidyr::unnest(lisa, moran)
#> Simple feature collection with 85 features and 40 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -5.139026 ymin: 42.33349 xmax: 8.23032 ymax: 51.08939
#> Geodetic CRS: WGS 84
#> # A tibble: 85 × 41
#> code_dept count ave_id_geo dept region department crime_pers crime_prop
#> <fct> <dbl> <dbl> <int> <fct> <fct> <int> <int>
#> 1 01 1 49 1 E Ain 28870 15890
#> 2 02 1 812 2 N Aisne 26226 5521
#> 3 03 1 1418 3 C Allier 26747 7925
#> 4 04 1 1603 4 E Basses-Alpes 12935 7289
#> 5 05 1 1802 5 E Hautes-Alpes 17488 8174
#> 6 07 1 2249 7 S Ardeche 9474 10263
#> 7 08 1 35395 8 N Ardennes 35203 8847
#> 8 09 1 2526 9 S Ariege 6173 9597
#> 9 10 1 34410 10 E Aube 19602 4086
#> 10 11 1 2807 11 S Aude 15647 10431
#> # … with 75 more rows, and 33 more variables: literacy <int>, donations <int>,
#> # infants <int>, suicides <int>, main_city <ord>, wealth <int>,
#> # commerce <int>, clergy <int>, crime_parents <int>, infanticide <int>,
#> # donation_clergy <int>, lottery <int>, desertion <int>, instruction <int>,
#> # prostitutes <int>, distance <dbl>, area <int>, pop1831 <dbl>,
#> # geometry <MULTIPOLYGON [°]>, nb <nb>, wt <list>, ii <dbl>, eii <dbl>,
#> # var_ii <dbl>, z_ii <dbl>, p_ii <dbl>, p_ii_sim <dbl>, p_folded_sim <dbl>, …