Last chance! 50% off unlimited learning
Sale ends in
Calculate the local Moran's I statistic for model residuals.
ww_local_moran_i()
returns the statistic itself, while
ww_local_moran_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::localmoran_perm()
instead.
ww_local_moran_i(data, ...)ww_local_moran_i_vec(truth, estimate, wt, na_rm = FALSE, ...)
ww_local_moran_pvalue(data, ...)
ww_local_moran_pvalue_vec(truth, estimate, wt = NULL, na_rm = FALSE, ...)
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).
A data.frame
containing the columns specified by the truth
and estimate
arguments.
Additional arguments passed to spdep::localmoran()
.
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, a numeric
vector.
The column identifier for the predicted
results (that is also numeric
). As with truth
this can be
specified different ways but the primary method is to use an
unquoted variable name. For _vec()
functions, a numeric
vector.
A listw
object, for instance as created with ww_build_weights()
.
For data.frame input, may also be a function that takes data
and returns a
listw
object.
A logical
value indicating whether NA
values should be stripped before the computation proceeds.
These functions can be used for geographic or projected coordinate reference systems and expect 2D data.
Anselin, L. 1995. Local indicators of spatial association, Geographical Analysis, 27, pp 93–115. doi: 10.1111/j.1538-4632.1995.tb00338.x.
Sokal, R. R, Oden, N. L. and Thomson, B. A. 1998. Local Spatial Autocorrelation in a Biological Model. Geographical Analysis, 30, pp 331–354. doi: 10.1111/j.1538-4632.1998.tb00406.x
Other autocorrelation metrics:
ww_global_geary_c()
,
ww_global_moran_i()
,
ww_local_geary_c()
,
ww_local_getis_ord_g()
Other yardstick metrics:
ww_agreement_coefficient()
,
ww_global_geary_c()
,
ww_global_moran_i()
,
ww_local_geary_c()
,
ww_local_getis_ord_g()
,
ww_willmott_d()
guerry_model <- guerry
guerry_lm <- lm(Crm_prs ~ Litercy, guerry_model)
guerry_model$predictions <- predict(guerry_lm, guerry_model)
ww_local_moran_i(guerry_model, Crm_prs, predictions)
ww_local_moran_pvalue(guerry_model, Crm_prs, predictions)
wt <- ww_build_weights(guerry_model)
ww_local_moran_i_vec(
guerry_model$Crm_prs,
guerry_model$predictions,
wt = wt
)
ww_local_moran_pvalue_vec(
guerry_model$Crm_prs,
guerry_model$predictions,
wt = wt
)
Run the code above in your browser using DataLab