Skip to contents

Moran's I is calculated for each polygon based on the neighbor and weight lists.

Usage

local_moran(x, nb, wt, alternative = "two.sided", nsim = 499, ...)

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.

Value

a data.frame containing the columns ii, eii, var_ii, z_ii, p_ii, p_ii_sim, and p_folded_sim. For more details please see spdep::localmoran_perm().

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()

Examples

library(magrittr)
lisa <- guerry %>%
  dplyr::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: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441
#> CRS:           NA
#> # A tibble: 85 × 41
#>    code_dept count ave_id…¹  dept region depar…² crime…³ crime…⁴ liter…⁵ donat…⁶
#>    <fct>     <dbl>    <dbl> <int> <fct>  <fct>     <int>   <int>   <int>   <int>
#>  1 01            1       49     1 E      Ain       28870   15890      37    5098
#>  2 02            1      812     2 N      Aisne     26226    5521      51    8901
#>  3 03            1     1418     3 C      Allier    26747    7925      13   10973
#>  4 04            1     1603     4 E      Basses…   12935    7289      46    2733
#>  5 05            1     1802     5 E      Hautes…   17488    8174      69    6962
#>  6 07            1     2249     7 S      Ardeche    9474   10263      27    3188
#>  7 08            1    35395     8 N      Ardenn…   35203    8847      67    6400
#>  8 09            1     2526     9 S      Ariege     6173    9597      18    3542
#>  9 10            1    34410    10 E      Aube      19602    4086      59    3608
#> 10 11            1     2807    11 S      Aude      15647   10431      34    2582
#> # … with 75 more rows, 31 more variables: 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>, skewness <dbl>, …
#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names