Skip to contents

Calculate the local Gi* statistic.

Usage

local_gstar(x, nb, wt, alternative = "two.sided", ...)

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

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.

...

methods passed to spdep::localG() or spdep::localG_perm()

nsim

The number of simulations to run.

Value

a data.frame with columns:

  • gi: the observed statistic

  • e_gi: the permutation sample mean

  • var_gi: the permutation sample variance

  • p_value: the p-value using sample mean and standard deviation

  • p_folded_sim: p-value based on the implementation of Pysal which always assumes a two-sided test taking the minimum possible p-value

  • skewness: sample skewness

  • kurtosis: sample kurtosis

Examples

nb <- st_contiguity(guerry)
wt <- st_weights(nb)
x <- guerry$crime_pers

res <- local_gstar_perm(x, nb, wt)
head(res)
#>     gi_star       e_gi       var_gi    p_value p_sim p_folded_sim    skewness
#> 1  1.360828 0.01167442 3.638609e-06 0.17356816 0.188        0.094  0.05525138
#> 2  2.524710 0.01168944 2.660730e-06 0.01157939 0.020        0.010  0.13335915
#> 3  2.282585 0.01168625 2.770689e-06 0.02245485 0.024        0.012  0.16825515
#> 4 -1.846626 0.01191737 3.805436e-06 0.06480133 0.064        0.032  0.10840209
#> 5 -1.171323 0.01171928 4.536439e-06 0.24146900 0.248        0.124  0.16720799
#> 6 -2.046161 0.01184872 2.191061e-06 0.04074054 0.064        0.032 -0.07723405
#>      kurtosis
#> 1 -0.09784373
#> 2 -0.02578022
#> 3  0.10924414
#> 4 -0.08593495
#> 5 -0.24617489
#> 6 -0.05281547

res <- local_gstar(x, nb, wt)
head(res)
#> [1]  1.342359  2.595578  2.388872 -1.848187 -1.209736 -2.034142