Calculate the local Geary's C statistic for model residuals.
ww_local_geary_c() returns the statistic itself, while
ww_local_geary_pvalue() returns the associated p value.
These functions are meant to help assess model predictions, for instance by
identifying clusters of higher residuals than expected. For statistical
testing and inference applications, use spdep::localC_perm() instead.
Usage
ww_local_geary_c(data, ...)
ww_local_geary_c_vec(truth, estimate, wt, na_rm = FALSE, ...)
ww_local_geary_pvalue(data, ...)
ww_local_geary_pvalue_vec(truth, estimate, wt = NULL, na_rm = FALSE, ...)Arguments
- data
 A
data.framecontaining the columns specified by thetruthandestimatearguments.- ...
 Additional arguments passed to
spdep::localC()(forww_local_geary_c()) orspdep::localC_perm()(forww_local_geary_pvalue()).- truth
 The column identifier for the true results (that is
numeric). This should be an unquoted column name although this argument is passed by expression and supports quasiquotation (you can unquote column names). For_vec()functions, anumericvector.- estimate
 The column identifier for the predicted results (that is also
numeric). As withtruththis can be specified different ways but the primary method is to use an unquoted variable name. For_vec()functions, anumericvector.- wt
 A
listwobject, for instance as created withww_build_weights(). For data.frame input, may also be a function that takesdataand returns alistwobject.- na_rm
 A
logicalvalue indicating whetherNAvalues should be stripped before the computation proceeds.
Value
A tibble with columns .metric, .estimator, and .estimate and nrow(data)
rows of values.
For _vec() functions, a numeric vector of length(truth) (or NA).
Details
These functions can be used for geographic or projected coordinate reference systems and expect 2D data.
References
Anselin, L. 1995. Local indicators of spatial association, Geographical Analysis, 27, pp 93–115. doi: 10.1111/j.1538-4632.1995.tb00338.x.
Anselin, L. 2019. A Local Indicator of Multivariate Spatial Association: Extending Geary's C. Geographical Analysis, 51, pp 133-150. doi: 10.1111/gean.12164
See also
Other autocorrelation metrics:
ww_global_geary_c(),
ww_global_moran_i(),
ww_local_getis_ord_g(),
ww_local_moran_i()
Other yardstick metrics:
ww_agreement_coefficient(),
ww_global_geary_c(),
ww_global_moran_i(),
ww_local_getis_ord_g(),
ww_local_moran_i(),
ww_willmott_d()
Examples
guerry_model <- guerry
guerry_lm <- lm(Crm_prs ~ Litercy, guerry_model)
guerry_model$predictions <- predict(guerry_lm, guerry_model)
ww_local_geary_c(guerry_model, Crm_prs, predictions)
#> # A tibble: 85 × 3
#>    .metric       .estimator .estimate
#>    <chr>         <chr>          <dbl>
#>  1 local_geary_c standard       0.981
#>  2 local_geary_c standard       0.836
#>  3 local_geary_c standard       0.707
#>  4 local_geary_c standard       0.108
#>  5 local_geary_c standard       0.264
#>  6 local_geary_c standard       1.36 
#>  7 local_geary_c standard       3.64 
#>  8 local_geary_c standard       1.57 
#>  9 local_geary_c standard       0.867
#> 10 local_geary_c standard       0.737
#> # ℹ 75 more rows
ww_local_geary_pvalue(guerry_model, Crm_prs, predictions)
#> # A tibble: 85 × 3
#>    .metric            .estimator .estimate
#>    <chr>              <chr>          <dbl>
#>  1 local_geary_pvalue standard       0.204
#>  2 local_geary_pvalue standard       0.214
#>  3 local_geary_pvalue standard       0.155
#>  4 local_geary_pvalue standard       0.105
#>  5 local_geary_pvalue standard       0.325
#>  6 local_geary_pvalue standard       0.146
#>  7 local_geary_pvalue standard       0.421
#>  8 local_geary_pvalue standard       0.209
#>  9 local_geary_pvalue standard       0.807
#> 10 local_geary_pvalue standard       0.480
#> # ℹ 75 more rows
wt <- ww_build_weights(guerry_model)
ww_local_geary_c_vec(
  guerry_model$Crm_prs,
  guerry_model$predictions,
  wt = wt
)
#>  [1] 0.981119438 0.836402177 0.707464373 0.108332465 0.264075824 1.361485477
#>  [7] 3.641239412 1.571824022 0.867252524 0.737094462 0.573376555 0.001605731
#> [13] 1.891988440 1.152840284 1.029320931 0.297642850 1.219953394 1.934113868
#> [19] 1.632566652 0.441916658 5.202733790 0.921953310 3.084515822 0.237218594
#> [25] 1.346684045 1.051652204 0.419414691 0.217280214 0.794409207 0.243971372
#> [31] 0.376678958 0.139152907 0.711305633 3.096840680 1.974463944 0.922230710
#> [37] 1.032031759 0.339464386 0.933794842 1.910440700 0.937597672 0.625628647
#> [43] 0.376707677 2.692250283 1.288784962 0.798443065 1.671895951 1.310183326
#> [49] 2.347513577 0.845204889 0.302940809 2.291804447 0.881999216 0.412051312
#> [55] 2.006031605 0.561239582 0.375776092 1.853716391 1.191472387 1.146802970
#> [61] 1.857618679 0.149044974 0.614228825 0.755373475 1.287962784 1.447534518
#> [67] 1.236607966 0.962394651 0.338400653 1.914478855 0.641340157 2.146993342
#> [73] 0.703881855 1.417638272 0.692636715 1.765618175 0.246058853 0.700262130
#> [79] 0.002876896 0.057575267 0.420878038 2.025012395 2.525093274 1.053335832
#> [85] 1.030009749
ww_local_geary_pvalue_vec(
  guerry_model$Crm_prs,
  guerry_model$predictions,
  wt = wt
)
#>  [1] 0.22397076 0.24452209 0.17638453 0.13126997 0.34256463 0.17788325
#>  [7] 0.42428895 0.20524353 0.77536774 0.41755829 0.02291064 0.14629038
#> [13] 0.31591487 0.89888952 0.50499868 0.19420887 0.76897787 0.54866832
#> [19] 0.07397845 0.18135231 0.50402303 0.78474281 0.67087150 0.12165354
#> [25] 0.87589859 0.98828466 0.23001988 0.09235934 0.62770539 0.10955518
#> [31] 0.21678555 0.14837468 0.47489966 0.61725226 0.06397186 0.83352097
#> [37] 0.37619926 0.28373539 0.83789431 0.89252219 0.65075012 0.55044611
#> [43] 0.16780829 0.23817444 0.79538937 0.04546472 0.25590490 0.19066757
#> [49] 0.15671385 0.17841602 0.05838159 0.74681212 0.43566136 0.22670313
#> [55] 0.93525527 0.18877035 0.21217560 0.63917342 0.23631591 0.95224729
#> [61] 0.30584030 0.27309526 0.33046237 0.18133101 0.50207272 0.39000305
#> [67] 0.71010019 0.76702396 0.02326828 0.07726186 0.52516304 0.17090430
#> [73] 0.36933518 0.51393324 0.54143723 0.08421472 0.10858934 0.30380435
#> [79] 0.15460527 0.06007115 0.27560642 0.53497684 0.06869429 0.95430057
#> [85] 0.99218585
