diff --git a/.vscode/settings.json b/.vscode/settings.json index 52e16bc..e4cb716 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -100,6 +100,8 @@ "scoped_allocator": "cpp", "valarray": "cpp", "geodaweight.h": "c", - "filesystem": "cpp" + "filesystem": "cpp", + "numbers": "cpp", + "semaphore": "cpp" } } \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 4893a1e..9b637f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: rgeoda Type: Package Title: R Library for Spatial Data Analysis -Version: 0.0.8-4 -Date: 2021-08-04 +Version: 0.0.8-6 +Date: 2021-09-07 Authors@R: c(person(given = "Xun", family = "Li", email="lixun910@gmail.com", role=c("aut","cre")), person(given = "Luc", family = "Anselin", email="anselin@uchicago.edu", role="aut")) diff --git a/NAMESPACE b/NAMESPACE index 5ba36ab..878a198 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,7 @@ export(has_isolates) export(hinge15_breaks) export(hinge30_breaks) export(is_symmetric) +export(join_count_ratio) export(kernel_knn_weights) export(kernel_weights) export(knn_weights) @@ -36,6 +37,7 @@ export(lisa_num_nbrs) export(lisa_pvalues) export(lisa_values) export(local_bijoincount) +export(local_bimoran) export(local_g) export(local_geary) export(local_gstar) @@ -46,6 +48,7 @@ export(local_multigeary) export(local_multijoincount) export(local_multiquantilelisa) export(local_quantilelisa) +export(make_spatial) export(max_neighbors) export(maxp_greedy) export(maxp_sa) @@ -72,6 +75,7 @@ export(sf_to_geoda) export(skater) export(sp_to_geoda) export(spatial_lag) +export(spatial_validation) export(stddev_breaks) export(update_weights) export(weights_sparsity) diff --git a/R/RcppExports.R b/R/RcppExports.R index acbb431..e7763bb 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -37,6 +37,18 @@ p_azp_tabu <- function(p, xp_w, data, n_vars, tabu_length, conv_tabu, bound_vals .Call('_rgeoda_p_azp_tabu', PACKAGE = 'rgeoda', p, xp_w, data, n_vars, tabu_length, conv_tabu, bound_vals, min_bound, inits, init_regions, scale_method, distance_method, seed) } +p_spatialvalidation <- function(xp_geoda, clusters, xp_w) { + .Call('_rgeoda_p_spatialvalidation', PACKAGE = 'rgeoda', xp_geoda, clusters, xp_w) +} + +p_joincount_ratio <- function(clusters, xp_w) { + .Call('_rgeoda_p_joincount_ratio', PACKAGE = 'rgeoda', clusters, xp_w) +} + +p_make_spatial <- function(clusters, xp_w) { + .Call('_rgeoda_p_make_spatial', PACKAGE = 'rgeoda', clusters, xp_w) +} + p_LISA__Run <- function(xp) { invisible(.Call('_rgeoda_p_LISA__Run', PACKAGE = 'rgeoda', xp)) } @@ -89,6 +101,10 @@ p_localmoran <- function(xp_w, data, permutations, permutation_method, significa .Call('_rgeoda_p_localmoran', PACKAGE = 'rgeoda', xp_w, data, permutations, permutation_method, significance_cutoff, cpu_threads, seed) } +p_bi_localmoran <- function(xp_w, data1, data2, permutations, permutation_method, significance_cutoff, cpu_threads, seed) { + .Call('_rgeoda_p_bi_localmoran', PACKAGE = 'rgeoda', xp_w, data1, data2, permutations, permutation_method, significance_cutoff, cpu_threads, seed) +} + p_eb_rate <- function(event_data, base_data) { .Call('_rgeoda_p_eb_rate', PACKAGE = 'rgeoda', event_data, base_data) } diff --git a/R/clustering.R b/R/clustering.R index e378459..af1e6e0 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -622,3 +622,98 @@ azp_tabu<- function(p, w, df, tabu_length=10, conv_tabu=10, bound_variable=data. return(p_azp_tabu(p, w$GetPointer(), df, n_vars, tabu_length, conv_tabu, bound_values, min_bound, inits, initial_regions, scale_method, distance_method, random_seed)) } + +############################################################ +#' @title Spatial Validation +#' @description Spatial validation provides a collection of validation measures including +#' 1. fragmentations (entropy, simpson), 2. join count ratio, 3. compactness (isoperimeter quotient) +#' and 4. diameter. +#' @param sf_obj An sf (simple feature) object +#' @param clusters A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) +#' @param w An instance of Weight class +#' @return A list with names "Is Spatially Constrained", "Fragmentation", "Join Count Ratio", +#' "Compactness", and "Diameter". +#' @examples +#' \dontrun{ +#' library(sf) +#' guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +#' guerry <- st_read(guerry_path) +#' queen_w <- queen_weights(guerry) +#' data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +#' clusters <- skater(5, queen_w, data) +#' results <- spatial_validation(guerry, clusters, queen_w) +#' results +#' } +#' @export +spatial_validation <- function(sf_obj, clusters, w) { + if (w$num_obs < 1) { + stop("The weights is not valid.") + } + + geoda_obj <- getGeoDaObj(sf_obj) + + if (geoda_obj$GetNumObs() <=0) { + stop("gda object is not valid.") + } + + return (p_spatialvalidation(geoda_obj$GetPointer(), clusters, w$GetPointer())); +} + +############################################################ +#' @title Join Count Ratio +#' @description Join count ratio is the join counts, the number of times a category is surrounded +#' by neighbors of the same category, over the total number of neighbors after converting +#' each category to a dummy variable. +#' @param clusters A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) +#' @param w An instance of Weight class +#' @return A data.frame with names "Cluster", "N", "Neighbors", "Join Count", "Ratio" +#' @examples +#' \dontrun{ +#' library(sf) +#' guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +#' guerry <- st_read(guerry_path) +#' queen_w <- queen_weights(guerry) +#' data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +#' clusters <- skater(5, queen_w, data) +#' results <- join_count_ratio(clusters, queen_w) +#' results +#' } +#' @export +join_count_ratio<- function(clusters, w) { + if (w$num_obs < 1) { + stop("The weights is not valid.") + } + + return (p_joincount_ratio(clusters, w$GetPointer())); +} + +############################################################ +#' @title Make Spatial +#' @description Make spatially constrained clusters from spatially non-constrained clusters +#' using the contiguity information from the input weights +#' @param clusters A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) +#' @param w An instance of Weight class +#' @return A vector of categorical values (cluster classification) +#' @examples +#' \dontrun{ +#' library(sf) +#' guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +#' guerry <- st_read(guerry_path) +#' data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +#' clusters <- kmeans(5, data) +#' queen_w <- queen_weights(guerry) +#' results <- make_spatial(clusters, queen_w) +#' results +#' } +#' @export +make_spatial <- function(clusters, w) { + if (w$num_obs < 1) { + stop("The weights is not valid.") + } + + if (w$num_obs != length(clusters)) { + stop("The weights doesn not match with the size of input clusters.") + } + + return (p_make_spatial(clusters, w$GetPointer())); +} \ No newline at end of file diff --git a/R/lisa.R b/R/lisa.R index 7ec8c3c..b21db10 100644 --- a/R/lisa.R +++ b/R/lisa.R @@ -316,6 +316,60 @@ local_moran <- function(w, df, permutations=999, permutation_method="complete", return(LISA$new(p_LISA(lisa_obj))) } +################################################################# +#' @title Bivariate Local Moran Statistics +#' @description The function to apply bivariate local Moran statistics +#' @param w An instance of Weight object +#' @param df A data frame with two selected variable. E.g. guerry[c('Crm_prs','Litercy')] +#' @param permutations (optional) The number of permutations for the LISA +#' computation +#' @param permutation_method (optional) The permutation method used for the +#' LISA computation. Options are {'complete', 'lookup'}. Default is 'complete'. +#' @param significance_cutoff (optional) A cutoff value for significance +#' p-values to filter not-significant clusters +#' @param cpu_threads (optional) The number of cpu threads used for parallel +#' LISA computation +#' @param seed (optional) The seed for random number generator +#' @return An instance of LISA-class +#' @examples +#' library(sf) +#' guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +#' guerry <- st_read(guerry_path) +#' queen_w <- queen_weights(guerry) +#' lisa <- local_bimoran(queen_w, guerry[c('Crm_prs','Litercy')]) +#' lms <- lisa_values(lisa) +#' lms +#' @export +local_bimoran <- function(w, df, permutations=999, permutation_method="complete", + significance_cutoff=0.05, cpu_threads=6, + seed=123456789) { + if (w$num_obs <= 0) { + stop("Weights object is not valid.") + } + + if (inherits(df, "data.frame") == FALSE) { + stop("The input data needs to be a data.frame.") + } + + num_vars <- length(df) + + if (inherits(df, "sf")) { + num_vars <- num_vars - 1 + } + + if (num_vars != 2) { + stop("Two variables are required for bivariate local moran.") + } + + data1 <- df[[1]] + data2 <- df[[2]] + + lisa_obj <- p_bi_localmoran(w$GetPointer(), data1, data2, permutations, + permutation_method, significance_cutoff, + cpu_threads, seed) + return(LISA$new(p_LISA(lisa_obj))) +} + ################################################################# #' @title Local Moran with Empirical Bayes(EB) Rate #' @description The function to apply local Moran with EB Rate statistics. The diff --git a/README.md b/README.md index 37bb133..e807b46 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ https://geodacenter.github.io/rgeoda/reference/ * Spatial Autocorrelation * Local Moran + * Bivariate Local Moran * Local Moran EB Rates * Local Geary * Local Getis-Ord @@ -93,6 +94,13 @@ https://geodacenter.github.io/rgeoda/reference/ * greedy * Tabu Search * Simulated Annealing + * Join Count Ratio + * Spatial Validation + * Fragmentation + * Join Count Ratio + * Compactness + * Diameter + * Make Spatial ## Build and install from source code diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..0643de9 --- /dev/null +++ b/docs/404.html @@ -0,0 +1,157 @@ + + + +
+ + + + +vignettes/rgeoda_tutorial.Rmd
+ rgeoda_tutorial.Rmd
rgeoda
is an R library for spatial data analysis. It is an R wrapper of the libgeoda C++ library, which is built based on the GeoDa
software. The version used in this tutorial is version 0.0.8.
rgeoda
+The rgeoda package can be installed using “install.packages()” command:
+install.packages("rgeoda")
+, and then can be loaded using the customary “library()” command:
+ +## Loading required package: digest
+In addition, the package sf needs to be loaded, since it is a dependency:
+ +## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
+The rgeoda package for R relies on the sf (simple features) package for basic spatial data handling functions. In a typical R workflow, one first reads a shape file or other GIS format file with the data using the sf st_read(file path) command. For example, to load the ESRI Shapefile Guerry.shp
comes with the package:
+guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
+guerry <- st_read(guerry_path)
## Reading layer `Guerry' from data source
+## `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp'
+## using driver `ESRI Shapefile'
+## Simple feature collection with 85 features and 29 fields
+## Geometry type: MULTIPOLYGON
+## Dimension: XY
+## Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441
+## Projected CRS: NTF (Paris) / Lambert zone II
+Once the spatial object has been created, it can be used to compute a spatial weights matrix using one of the several weights functions in rgeoda.
+Spatial weights are central components in spatial data analysis. The spatial weights represent the possible spatial interactions between observations in space. rgeoda
provides 6 functions to create 4 different types of spatial weights:
queen_weights()
, rook_weights()
+distance_weights()
+knn_weights()
+distance_weights()
and knn_weights()
with kernel parametersContiguity means that two spatial units share a common border of non-zero length. Operationally, we can further distinguish between a rook and a queen criterion of contiguity, in analogy to the moves allowed for the such-named pieces on a chess board. The queen criterion is somewhat more encompassing and defines neighbors as spatial units sharing a common edge or a common vertex.
+To create a Queen contiguity weights, one can call the function
+
+queen_weights(sf_obj, order=1, include_lower_order = False, precision_threshold = 0)
For example, to create a Queen contiguity weights using the sf object guerry
:
+queen_w <- queen_weights(guerry)
+summary(queen_w)
## name value
+## 1 number of observations: 85
+## 2 is symmetric: TRUE
+## 3 sparsity: 0.0581314878892734
+## 4 # min neighbors: 2
+## 5 # max neighbors: 8
+## 6 # mean neighbors: 4.94117647058824
+## 7 # median neighbors: 5
+## 8 has isolates: FALSE
+The function queen_weights()
returns an instance of Weight
object. One can access the meta data of the spatial weights by accessing the attributes of GeoDaWeight
object:
Weight
object
+is_symmetric(queen_w)
## [1] TRUE
+
+has_isolates(queen_w)
## [1] FALSE
+
+weights_sparsity(queen_w)
## [1] 0.05813149
+To access the details of the weights: e.g. list the neighbors of a specified observation:
+
+nbrs <- get_neighbors(queen_w, idx = 1)
+cat("\nNeighbors of the 1-st observation are:", nbrs)
##
+## Neighbors of the 1-st observation are: 36 37 67 69
+To compute the spatial lag of a specified observation by passing the values of the selected variable:
+
+lag <- spatial_lag(queen_w, guerry['Crm_prs'])
+lag
## Spatial.Lag
+## 1 23047.50
+## 2 26919.67
+## 3 26195.50
+## 4 14401.25
+## 5 15038.67
+## 6 15749.00
+## 7 22111.67
+## 8 13672.33
+## 9 22859.20
+## 10 11475.20
+## 11 12200.14
+## 12 13278.67
+## 13 24734.00
+## 14 11752.83
+## 15 17992.60
+## 16 21974.40
+## 17 26711.00
+## 18 19344.00
+## 19 23696.71
+## 20 25108.67
+## 21 21643.17
+## 22 18306.00
+## 23 24280.00
+## 24 14451.60
+## 25 21047.67
+## 26 21421.33
+## 27 25961.50
+## 28 10869.83
+## 29 13415.67
+## 30 17172.17
+## 31 20238.25
+## 32 12504.25
+## 33 26723.00
+## 34 21772.83
+## 35 26462.20
+## 36 19252.00
+## 37 24683.20
+## 38 20607.25
+## 39 24412.00
+## 40 19373.71
+## 41 16000.20
+## 42 23993.25
+## 43 20337.86
+## 44 16818.67
+## 45 17113.83
+## 46 13013.00
+## 47 22133.00
+## 48 24093.75
+## 49 25661.67
+## 50 22190.17
+## 51 29030.00
+## 52 16951.00
+## 53 24509.00
+## 54 24982.75
+## 55 19491.50
+## 56 24176.00
+## 57 27639.67
+## 58 21274.33
+## 59 24510.33
+## 60 30166.00
+## 61 23459.00
+## 62 16184.00
+## 63 18002.00
+## 64 10910.00
+## 65 16251.25
+## 66 15572.00
+## 67 25884.25
+## 68 23020.60
+## 69 26495.00
+## 70 24690.50
+## 71 17339.00
+## 72 25522.33
+## 73 18970.00
+## 74 19701.83
+## 75 21841.00
+## 76 24520.40
+## 77 14025.80
+## 78 14565.17
+## 79 13306.67
+## 80 12579.00
+## 81 21529.50
+## 82 23474.50
+## 83 24373.17
+## 84 19900.50
+## 85 23373.60
+The rook criterion defines neighbors by the existence of a common edge between two spatial units. To create a Rook contiguity weights, one can call function:
+
+rook_weights(sf_obj, order=1,include_lower_order=False, precision_threshold = 0)
For example, to create a Rook contiguity weights using the sf object guerry
:
+rook_w <- rook_weights(guerry)
+summary(rook_w)
## name value
+## 1 number of observations: 85
+## 2 is symmetric: TRUE
+## 3 sparsity: 0.0581314878892734
+## 4 # min neighbors: 2
+## 5 # max neighbors: 8
+## 6 # mean neighbors: 4.94117647058824
+## 7 # median neighbors: 5
+## 8 has isolates: FALSE
+The weights we created are in memory. To save the weights to a file, one can call the function:
+
+save_weights(gda_w, id_variable, out_path, layer_name = "")
The id_variable
defines the unique value of each observation when saving a weights file
The layer_name
is the layer name of loaded dataset. For a ESRI shapefile, the layer name is the file name without the suffix (e.g. Guerry).
For example, using Guerry dataset, the column “CODE_DE” can be used as a key to save a weights file:
+
+save_weights(rook_w, guerry['CODE_DE'], out_path = '/Users/xun/Downloads/Guerry_r.gal',
+ layer_name = 'Guerry')
## [1] FALSE
+The most straightforward spatial weights matrix constructed from a distance measure is obtained when i and j are considered neighbors whenever j falls within a critical distance band from i. In order to start the distance based neighbors, we first need to compute a threshold value. rgeoda
provides a function min_distthreshold
to help you find a optimized distance threshold that guarantees that every observation has at least one neighbor:
min_distthreshold(GeoDa gda, bool is_arc = False, is_mile = True)
+To create a Distance based weights, one can call the function `distance_weights`:
Then, with this distance threshold, we can create a distance-band weights using the function:
+
+distance_weights(geoda_obj, dist_thres, power=1.0, is_inverse=False, is_arc=False, is_mile=True)
For example:
+
+dist_thres <- min_distthreshold(guerry)
+dist_thres
## [1] 96726.14
+
+dist_w <- distance_weights(guerry, dist_thres)
+summary(dist_w)
## name value
+## 1 number of observations: 85
+## 2 is symmetric: TRUE
+## 3 sparsity: 0.0434602076124567
+## 4 # min neighbors: 1
+## 5 # max neighbors: 7
+## 6 # mean neighbors: 3.69411764705882
+## 7 # median neighbors: 4
+## 8 has isolates: FALSE
+A special case of distance based weights is K-Nearest neighbor weights, in which every obersvation will have exactly k neighbors. It can be used to avoid the problem of isolate in distance-band weights when a smaller cut-off distance is used. To create a KNN weights, we can call the function knn_weights
:
+knn_weights(gda, k, power = 1.0,is_inverse = False, is_arc = False, is_mile = True)
For example, to create a 6-nearest neighbor weights using Guerry:
+
+knn6_w <- knn_weights(guerry, 6)
+summary(knn6_w)
## name value
+## 1 number of observations: 85
+## 2 is symmetric: FALSE
+## 3 sparsity: 0.0705882352941176
+## 4 # min neighbors: 6
+## 5 # max neighbors: 6
+## 6 # mean neighbors: 6
+## 7 # median neighbors: 6
+## 8 has isolates: FALSE
+Kernel weights apply kernel function to determine the distance decay in the derived continuous weights kernel. The kernel weights are defined as a function K(z) of the ratio between the distance dij from i to j, and the bandwidth hi, with z=dij/hi.
+The kernel functions include
+Two functions are provided in rgeoda
to create kernel weights.
kernel_weights
for Kernel Weights with adaptive bandwidthTo create a kernel weights with fixed bandwith:
+
+bandwidth <- min_distthreshold(guerry)
+kernel_w <- kernel_weights(guerry, bandwidth, kernel_method = "uniform")
+summary(kernel_w)
## name value
+## 1 number of observations: 85
+## 2 is symmetric: FALSE
+## 3 sparsity: 0.0434602076124567
+## 4 # min neighbors: 1
+## 5 # max neighbors: 7
+## 6 # mean neighbors: 3.69411764705882
+## 7 # median neighbors: 4
+## 8 has isolates: FALSE
+The arguments is_inverse
, power
, is_arc
and is_mile
are the same with the distance based weights. Additionally, kernel_weights
has another argument that user can specify:
use_kernel_diagonals
+(optional) FALSE (default) or TRUE, apply kernel on the diagonal of weights matrix
+kernel_knn_weights
for Kernel Weights with adaptive bandwidthTo create a kernel weights with adaptive bandwidth or using max Knn distance as bandwidth:
+
+adptkernel_w = kernel_knn_weights(guerry, 6, "uniform")
+
+summary(adptkernel_w)
## name value
+## 1 number of observations: 85
+## 2 is symmetric: FALSE
+## 3 sparsity: 0.0705882352941176
+## 4 # min neighbors: 6
+## 5 # max neighbors: 6
+## 6 # mean neighbors: 6
+## 7 # median neighbors: 6
+## 8 has isolates: FALSE
+This kernel weights function two more arguments that user can specify:
+adaptive_bandwidth
+(optional) TRUE (default) or FALSE: TRUE use adaptive bandwidth calculated using distance of k-nearest neithbors, FALSE use max distance of all observation to their k-nearest neighbors
+
+use_kernel_diagonals
+(optional) FALSE (default) or TRUE, apply kernel on the diagonal of weights matrix
+rgeoda
provides following methods for local spatial autocorrelation statistics:
For more information about the local spatial autocorrelation statisticis, please read Dr. Luc Anselin’s lab notes: http://geodacenter.github.io/workbook/6a_local_auto/lab6a.html.
+The Local Moran statistic is a method to identify local clusters and local spatial outliers. For example, we can call the function local_moran()
with the created Queen weights and the data “crm_prp = guerry[‘Crm_prp’]” as input parameters:
+crm_prp = guerry["Crm_prp"]
+lisa <- local_moran(queen_w, crm_prp)
The local_moran()
function will return a lisa
object, and we can access its values/results of lisa computation using the following functions:
For example, we can call the function lisa_values()
to get the values of the local Moran:
+lms <- lisa_values(gda_lisa = lisa)
+lms
## [1] 0.0154319783 0.3270633224 0.0212952962 0.0046105448 -0.0028342407
+## [6] 0.4149377158 -0.1379463091 0.0998657692 0.2823176310 0.1218745112
+## [11] -0.0951205417 0.0326111938 0.3878324535 1.1888723840 -0.6452792226
+## [16] -0.3096492740 0.3662775143 2.0375343539 -0.0050154800 0.0697110572
+## [21] 2.2720355722 0.2886391551 -0.0070189726 -0.0009906605 0.9517469793
+## [26] 0.7648322095 0.0432039929 -0.0045362842 -0.0964911860 0.0952360887
+## [31] 0.0100895206 -0.0109401003 -0.0544245927 -0.0345553975 0.0887531916
+## [36] 0.0954232056 0.0383617454 -0.1776714441 0.1638208393 1.2309154898
+## [41] 2.9077203402 -0.0396340261 0.4458735227 0.2491123240 0.0905643622
+## [46] -0.6212977834 -0.0308773407 0.0375870399 0.2270376112 -0.0918254739
+## [51] -0.0112400086 0.1085584763 -0.0055113129 -0.0027097589 0.7235016208
+## [56] 0.0163129939 0.4246564560 0.3787307767 -0.0597158189 0.5050011802
+## [61] 2.7632125275 0.0656510809 0.1771899330 -0.0572150317 0.4943795537
+## [66] 0.2870386197 -1.4593300774 -0.0055305930 0.4895990016 -0.0324125662
+## [71] 2.1366499813 0.9041683235 0.7053678641 1.4098290925 0.0051652159
+## [76] 0.2238144189 -0.1621373954 0.0195632289 -0.3233724187 -0.0337778226
+## [81] 0.0118189869 -0.1164679533 -0.5699624657 -0.0859634996 0.2085373916
+To get the pseudo-p values of significance of local Moran computation:
+
+pvals <- lisa_pvalues(lisa)
+pvals
## [1] 0.414 0.123 0.001 0.474 0.452 0.087 0.243 0.326 0.299 0.303 0.237 0.461
+## [13] 0.248 0.015 0.178 0.166 0.124 0.003 0.456 0.346 0.053 0.145 0.431 0.425
+## [25] 0.005 0.037 0.464 0.395 0.138 0.316 0.495 0.431 0.359 0.129 0.295 0.058
+## [37] 0.090 0.231 0.258 0.018 0.026 0.455 0.073 0.057 0.222 0.023 0.369 0.338
+## [49] 0.282 0.359 0.483 0.252 0.450 0.434 0.138 0.327 0.063 0.005 0.097 0.292
+## [61] 0.001 0.217 0.237 0.126 0.145 0.344 0.008 0.340 0.079 0.300 0.033 0.142
+## [73] 0.001 0.001 0.460 0.005 0.212 0.384 0.110 0.409 0.455 0.353 0.006 0.287
+## [85] 0.128
+To get the cluster indicators of local Moran computation:
+
+cats <- lisa_clusters(lisa, cutoff = 0.05)
+cats
## [1] 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0
+## [39] 0 1 1 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 2 0 0 1 0 0 0 0 0 3 0 0 0 2 0 2 2 0 2
+## [77] 0 0 0 0 0 0 3 0 0
+The predefined values of the indicators of LISA cluster are:
+0 Not significant
+1 High-High
+2 Low-Low
+3 High-Low
+4 Low-High
+5 Undefined
+6 Isolated
+which can be accessed via the function lisa_labels()
:
+lbls <- lisa_labels(lisa)
+lbls
## [1] "Not significant" "High-High" "Low-Low" "Low-High"
+## [5] "High-Low" "Undefined" "Isolated"
+By default, the local_moran()
function will run with some default parameters, e.g.:
significance_cutoff: 0.05
+permutation: 999
+permutation_method: 'complete'
+cpu_threads: 6
+seed (for random number generator): 123456789
+, which are identical to GeoDa desktop software so to replicate the results in GeoDa software. You can set different values when calling the lisa functions.
+For example, re-run the above local Moran example using 9,999 permutations.
+
+lisa <- local_moran(queen_w, crm_prp, permutations = 9999)
Then, we can use the same lisa
object to get the new results after 9,999 permutations:
+pvals <- lisa_pvalues(lisa)
+pvals
## [1] 0.4187 0.1265 0.0004 0.4679 0.4545 0.0728 0.2312 0.3071 0.3115 0.3088
+## [11] 0.2187 0.4834 0.2686 0.0102 0.2024 0.1789 0.1320 0.0020 0.4558 0.3519
+## [21] 0.0479 0.1376 0.4441 0.4195 0.0032 0.0388 0.4733 0.4187 0.1278 0.3300
+## [31] 0.4939 0.4427 0.3393 0.1419 0.2714 0.0606 0.0724 0.2247 0.2628 0.0185
+## [41] 0.0214 0.4899 0.0719 0.0589 0.2288 0.0189 0.3759 0.3217 0.2812 0.3735
+## [51] 0.4695 0.2743 0.4518 0.4286 0.1471 0.3222 0.0647 0.0025 0.0917 0.2812
+## [61] 0.0001 0.2419 0.2462 0.1266 0.1270 0.3553 0.0094 0.3123 0.0724 0.2975
+## [71] 0.0307 0.1320 0.0001 0.0002 0.4633 0.0056 0.2162 0.3681 0.1335 0.4069
+## [81] 0.4536 0.3547 0.0035 0.3096 0.1277
+rgeoda
uses GeoDa
C++ code, in which multi-threading is used to accelerate the computation of LISA. We can use the argument ncpu
to specify how many threads to run the computation:
+lisa <- local_moran(queen_w, crm_prp, cpu_threads = 4)
Get the False Discovery Rate value based on current pseudo-p values:
+
+fdr <- lisa_fdr(lisa, 0.05)
+fdr
## [1] 0.0005882353
+Then, one can set the FDR value as the cutoff p-value to filter the cluster results:
+
+cat_fdr <- lisa_clusters(lisa, cutoff = fdr)
+cat_fdr
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [39] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [77] 0 0 0 0 0 0 0 0 0
+Local Geary is a type of LISA that focuses on squared differences/dissimilarity. A small value of the local geary statistics suggest positive spatial autocorrelation, whereas large values suggest negative spatial autocorrelation. For more details, please read: http://geodacenter.github.io/workbook/6b_local_adv/lab6b.html#local-geary
+For example, we can call the function local_geary() with the created Queen weights and the data “crm_prp” as input parameters:
+
+geary_crmprp <- local_geary(queen_w, crm_prp)
To get the cluster indicators of the local Geary computation:
+
+lisa_clusters(geary_crmprp)
## [1] 0 2 4 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 2 2 0 0 0 0 0 0 0 4 0 0 0 0
+## [39] 0 0 1 0 0 0 1 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 2 0 0
+## [77] 0 0 0 0 0 0 4 0 0
+To get the pseudo-p values of the local Geary computation:
+
+lisa_pvalues(geary_crmprp)
## [1] 0.398 0.027 0.025 0.126 0.017 0.314 0.610 0.141 0.284 0.110 0.559 0.456
+## [13] 0.211 0.255 0.226 0.211 0.089 0.054 0.182 0.017 0.030 0.216 0.395 0.105
+## [25] 0.024 0.033 0.089 0.416 0.504 0.059 0.380 0.254 0.211 0.048 0.113 0.154
+## [37] 0.160 0.571 0.310 0.093 0.009 0.130 0.128 0.178 0.039 0.088 0.076 0.319
+## [49] 0.291 0.438 0.043 0.464 0.177 0.099 0.100 0.232 0.141 0.317 0.615 0.208
+## [61] 0.198 0.299 0.084 0.634 0.148 0.423 0.060 0.108 0.293 0.257 0.032 0.102
+## [73] 0.057 0.003 0.706 0.560 0.605 0.066 0.320 0.391 0.175 0.601 0.007 0.365
+## [85] 0.238
+To apply multivariate local geary, we need to define a string with the variable names and use this string to extract the relevant subset from the data frame. For example, we apply multivariate local geary on variables “Crm_prs”, “Crm_prp”, “Litercy”, “Donatns”, “Infants” and “Suicids”:
+
+data <-guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
+multigeary <- local_multigeary(queen_w, data)
To get the cluster indicators of the local Geary computation:
+
+lisa_clusters(multigeary)
## [1] 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 0
+## [39] 1 0 1 2 1 1 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 0 1
+## [77] 1 1 1 1 0 1 0 1 1
+There are two types of local Getis-Ord statistics: one is computing a ratio of the weighted average of the values in the neighboring locations, not including the value at the location; while another type of statistic includes the value at the location in both numerator and denominator. For more details, please read: http://geodacenter.github.io/workbook/6b_local_adv/lab6b.html#getis-ord-statistics
+A value larger than the mean suggests a high-high cluster or hot spot, a value smaller than the mean indicates a low-low cluster or cold spot.
+For example, we can call the function local_g()
with the created Queen weights and the data “crm_prp” as input parameters:
+localg_crmprp <- local_g(queen_w, crm_prp)
To get the cluster indicators of the local G computation:
+
+lisa_clusters(localg_crmprp)
## [1] 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0
+## [39] 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 1 0 0 0 0 0 1 0 0 0 2 0 2 2 0 2
+## [77] 0 0 0 0 0 0 1 0 0
+To get the pseudo-p values of the local G computation:
+
+lisa_pvalues(localg_crmprp)
## [1] 0.414 0.123 0.001 0.474 0.452 0.087 0.243 0.326 0.299 0.303 0.237 0.461
+## [13] 0.248 0.015 0.178 0.166 0.124 0.003 0.456 0.346 0.053 0.145 0.432 0.425
+## [25] 0.005 0.037 0.464 0.395 0.138 0.316 0.495 0.431 0.359 0.129 0.295 0.058
+## [37] 0.090 0.231 0.258 0.018 0.026 0.455 0.073 0.057 0.222 0.023 0.369 0.338
+## [49] 0.282 0.359 0.483 0.252 0.450 0.434 0.138 0.327 0.063 0.005 0.097 0.292
+## [61] 0.001 0.217 0.237 0.127 0.145 0.344 0.008 0.340 0.079 0.300 0.033 0.142
+## [73] 0.001 0.001 0.461 0.005 0.212 0.384 0.110 0.409 0.455 0.353 0.006 0.287
+## [85] 0.128
+For the second type of local Getis-Ord statistics, we can call the function local_gstar()
with the created Queen weights and the data “crm_prp” as input parameters:
+localgstar_crmprs <- local_gstar(queen_w, crm_prp)
+lisa_pvalues(localgstar_crmprs)
## [1] 0.414 0.123 0.001 0.474 0.452 0.087 0.243 0.326 0.299 0.303 0.237 0.461
+## [13] 0.248 0.015 0.178 0.166 0.124 0.003 0.456 0.346 0.053 0.145 0.432 0.425
+## [25] 0.005 0.037 0.464 0.395 0.138 0.316 0.495 0.431 0.359 0.129 0.295 0.058
+## [37] 0.090 0.231 0.258 0.018 0.026 0.455 0.073 0.057 0.222 0.023 0.369 0.338
+## [49] 0.282 0.359 0.483 0.252 0.450 0.434 0.138 0.327 0.063 0.005 0.097 0.292
+## [61] 0.001 0.217 0.237 0.127 0.145 0.344 0.008 0.340 0.079 0.300 0.033 0.142
+## [73] 0.001 0.001 0.461 0.005 0.212 0.384 0.110 0.409 0.455 0.353 0.006 0.287
+## [85] 0.128
+Local Join Count is a method to identify local clusters for binary data by using a local version of the so-called BB join count statistic. The statistic is only meaningful for those observations with value 1. For more details, please read http://geodacenter.github.io/workbook/6d_local_discrete/lab6d.html
+For example, we can call the function local_joincount()
with a Queen weights and the data “TopCrm”, which is a set of binary (0,1) values, as input parameters:
+top_crm <- guerry['TopCrm']
+localjc_crm <- local_joincount(queen_w, top_crm)
To get the pseudo-p values of the local Join Count computation:
+
+lisa_pvalues(localjc_crm)
## [1] 0.395 0.085 0.094 NA NA NA 0.255 NA NA NA NA NA
+## [13] NA NA NA NA NA NA 0.170 0.242 0.394 NA NA NA
+## [25] NA NA 0.111 NA NA NA NA NA NA 0.095 NA NA
+## [37] 0.189 NA NA 0.284 NA NA NA NA NA NA 0.218 0.378
+## [49] NA 0.367 0.037 0.233 0.174 0.392 NA 0.282 0.028 0.370 0.298 0.106
+## [61] NA NA NA NA NA NA NA NA 0.009 0.325 NA NA
+## [73] NA NA NA 0.041 NA NA NA NA NA NA NA NA
+## [85] NA
+To get the cluster indicators of the local Join Count computation:
+
+lisa_clusters(localjc_crm)
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [39] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1
+## [77] 0 0 0 0 0 0 0 0 0
+To get the number of neighbors of the local Join Count computation:
+
+lisa_num_nbrs(localjc_crm)
## [1] 4 6 6 4 3 7 3 3 5 5 7 3 3 6 5 5 6 6 7 3 6 7 2 5 6 6 2 6 6 6 4 4 6 6 5 6 5 4
+## [39] 6 7 5 4 7 6 6 5 8 4 6 6 5 4 5 4 2 6 3 6 6 2 6 3 3 2 4 2 4 5 7 6 2 3 8 6 5 5
+## [77] 5 6 3 6 4 6 6 6 5
+Bivariate Local Join Count means, in a bivariate local join count, the two events cannot happen in the same location. It is also called “no-colocation” join count. To demonstrate this function, we manually create a new variable:
+
+inv_crm <- 1 - as.data.frame(guerry[,"TopCrm"])[,1] # create no-location case
+guerry['Inv_Crm'] <- inv_crm
Now, top_crm and inv_crm are no-colocation bivariate cases. Then, we apply the local_bijoicount():
+
+jc <- local_bijoincount(queen_w, guerry[c('TopCrm', 'Inv_Crm')])
In case of co-location, a warning message will be raised “The bivariate local join count only applies on two variables with no-colocation.” , and one can use pygeoda.local_multijoincount() for co-location case.
+To get the cluster indicators of the multivariate local join count computation:
+
+lisa_pvalues(jc)
## [1] 0.106 0.013 0.017 NA NA NA 0.035 NA NA NA NA NA
+## [13] NA NA 0.135 NA NA NA 0.040 0.024 0.296 NA NA NA
+## [25] NA NA NA NA NA NA 0.208 NA NA 0.398 NA NA
+## [37] 0.047 NA NA 0.407 NA NA NA NA NA NA 0.487 0.098
+## [49] NA 0.292 0.007 0.416 0.035 0.101 NA 0.076 NA 0.305 0.086 NA
+## [61] NA NA NA NA NA NA NA NA 0.001 0.100 NA NA
+## [73] NA NA NA 0.005 NA NA NA NA NA NA NA NA
+## [85] NA
+To get the cluster indicators of the local Join Count computation:
+
+lisa_clusters(jc)
## [1] 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
+## [39] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1
+## [77] 0 0 0 0 0 0 0 0 0
+Co-location Local Join Count is for where two or more events happen in the same location. Therefore, the function local_multijoincount takes a list of variables with 0/1 values as the input parameter:
+
+bin_data <- guerry[c('TopWealth','TopWealth', 'TopLit')]
+jc <- local_multijoincount(queen_w, bin_data)
To get the cluster indicators of the multivariate local join count computation:
+
+lisa_pvalues(jc)
## [1] NA NA NA 0.256 0.205 NA NA NA NA NA NA NA
+## [13] NA NA NA NA NA NA NA NA NA NA NA NA
+## [25] NA NA NA NA NA NA NA NA NA NA NA NA
+## [37] 0.319 NA NA NA NA NA NA NA NA NA NA NA
+## [49] NA NA NA NA NA NA NA NA NA NA NA NA
+## [61] NA 0.175 0.192 NA NA NA NA 0.051 NA NA NA NA
+## [73] NA NA NA NA NA NA NA NA NA NA NA 0.348
+## [85] NA
+The quantile local spatial autocorrelation converte the continuous variable to a binary variable that takes the value of 1 for a specific quantile. Then appaly a local join count to the data converted. Two input parameters, k and q, need to be specified in the function pygeoda.quantile_lisa(): k is the number of quantiles (k > 2), and the q is the index of selected quantile lisa ranging from 1 to k.
+For example, the examples in section 4.1.5 can be simply implemented as
+
+qsa <- local_quantilelisa(queen_w, crm_prp, 5, 5)
To get the p-values and cluster indicators of the quantile LISA computation:
+
+lisa_pvalues(qsa)
## [1] 0.419 NA NA NA NA 0.376 NA 0.442 NA 0.257 NA NA
+## [13] NA 0.082 0.348 NA 0.277 0.010 NA NA 0.090 0.387 NA NA
+## [25] NA NA NA NA NA 0.271 NA 0.447 NA NA NA NA
+## [37] NA NA NA 0.026 0.003 NA NA NA NA NA NA NA
+## [49] NA NA NA NA NA NA NA NA NA NA NA NA
+## [61] 0.001 NA 0.465 NA NA NA NA NA 0.378 NA NA NA
+## [73] NA NA NA NA NA NA NA NA NA NA NA NA
+## [85] NA
+
+lisa_clusters(qsa)
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [39] 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [77] 0 0 0 0 0 0 0 0 0
+Multivariate Quantile LISA
+For multiple variables, the Quantile LISA can automatiaclly detect if it is the case of no-colocation, in which local_bijoincount() will be called internally, or the case of co-location, in which local_multijoincount() will be called internally.
+
+qsa <- local_multiquantilelisa(queen_w, guerry[c("TopCrm", "TopLit")], c(5,5), c(5,5))
To get the p-values and cluster indicators of the quantile LISA computation:
+
+lisa_pvalues(qsa)
## [1] NA 0.122 NA NA NA NA 0.023 NA NA NA NA NA
+## [13] NA NA NA NA NA NA 0.137 NA NA NA NA NA
+## [25] NA NA NA NA NA NA NA NA NA NA NA NA
+## [37] 0.412 NA NA NA NA NA NA NA NA NA NA NA
+## [49] NA 0.111 NA 0.323 0.012 NA NA NA NA 0.465 NA NA
+## [61] NA NA NA NA NA NA NA NA NA NA NA NA
+## [73] NA NA NA NA NA NA NA NA NA NA NA NA
+## [85] NA
+
+lisa_clusters(qsa)
## [1] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [39] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+## [77] 0 0 0 0 0 0 0 0 0
+The bivariate Local Moran’s I captures the relationship between the value for one variable at location i, and the average of the neighboring values for another variable. Please note this statistic needs to be interpreted with caution, since it ignores in-situ correlation between the two variables. The most meaningful application of the bivariate Local Moran statistic is comparing the same variable at two time periods. See: https://geodacenter.github.io/workbook/6c_local_multi/lab6c.html#bivariate-local-moran
+
+qsa <- local_bimoran(queen_w, guerry[c('Crm_prs', 'Litercy')])
Spatial clustering aims to group of a large number of geographic areas or points into a smaller number of regions based on similiarities in one or more variables. Spatially constrained clustering is needed when clusters are required to be spatially contiguous.
+There are three different approaches explicitly incorporate the contiguity constraint in the optimization process: SKATER, Redcap and Max-p. For more details, please read: * http://geodacenter.github.io/workbook/9c_spatial3/lab9c.html * http://geodacenter.github.io/workbook/9d_spatial4/lab9d.html
+For example, to apply spatial clustering on the Guerry dataset, we use the queen weights to define the spatial contiguity and select 6 variables for similarity measure: “Crm_prs”, “Crm_prp”, “Litercy”, “Donatns”, “Infants”, “Suicids”.
+
+data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
The Spatial C(K)luster Analysis by Tree Edge Removal(SKATER) algorithm introduced by Assuncao et al. (2006) is based on the optimal pruning of a minimum spanning tree that reflects the contiguity structure among the observations. It provides an optimized algorithm to prune to tree into several clusters that their values of selected variables are as similar as possible.
+The rgeoda
’s SKATER function is:
For example, to create 4 spatially contiguous clusters using Guerry dataset, the queen weights and the values of the 6 selected variables:
+
+guerry_clusters <- skater(4, queen_w, data)
+guerry_clusters
## $Clusters
+## [1] 3 2 3 1 1 1 2 1 2 1 1 1 2 1 1 3 3 3 2 4 3 1 2 1 2 2 4 1 1 1 1 1 4 3 4 1 2 1
+## [39] 4 3 3 4 2 1 1 1 4 4 2 2 4 2 2 4 2 3 2 2 4 2 3 1 1 1 2 2 1 2 3 4 2 2 2 2 3 2
+## [77] 1 1 1 1 3 3 3 2 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 57.89077 59.95242 28.72571 69.38030 62.30781 66.65809
+##
+## $`Total within-cluster sum of squares`
+## [1] 159.0849
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.3156447
+This skater() function returns a names list with names “Clusters”, “Total sum of squares”, “Within-cluster sum of squares”, “Total within-cluster sum of squares”, and “The ratio of between to total sum of squares”.
+REDCAP (Regionalization with dynamically constrained agglomerative clustering and partitioning) is developed by D. Guo (2008). Like SKATER, REDCAP starts from building a spanning tree in 3 different ways (single-linkage, average-linkage, and the complete-linkage). The single-linkage way leads to build a minimum spanning tree. Then, REDCAP provides 2 different ways (first-order and full-order constraining) to prune the tree to find clusters. The first-order approach with a minimum spanning tree is the same as SKATER. In GeoDa
and rgeoda
, the following methods are provided:
For example, to find 4 clusters using the same dataset and weights as above using REDCAP with Full-order and Complete-linkage method:
+
+redcap_clusters <- redcap(4, queen_w, data, "fullorder-completelinkage")
+redcap_clusters
## $Clusters
+## [1] 1 2 1 3 3 1 2 3 2 3 3 3 2 1 1 1 1 1 2 1 1 1 2 3 2 2 1 3 3 3 3 3 1 1 1 3 2 3
+## [39] 1 1 4 1 2 3 3 3 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 3 3 3 2 2 3 2 1 1 2 2 2 2 1 2
+## [77] 3 3 3 3 1 1 1 2 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 59.33033 55.01580 28.20272 68.58974 61.27232 54.63519
+##
+## $`Total within-cluster sum of squares`
+## [1] 176.9539
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.351099
+Spatially constrained hierarchical clustering is a special form of constrained clustering, where the constraint is based on contiguity (common borders). The method builds up the clusters using agglomerative hierarchical clustering methods: single linkage, complete linkage, average linkage and Ward’s method (a special form of centroid linkage). Meanwhile, it also maintains the spatial contiguity when merging two clusters.
+For example, to find 4 spatially constrained clusters using the same dataset and weights as above using Complete-linkage method:
+
+schc_clusters <- schc(4, queen_w, data, "complete")
+schc_clusters
## $Clusters
+## [1] 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+## [39] 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+## [77] 1 1 1 1 1 1 1 1 1
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 78.13831 54.75868 81.49771 63.48675 80.60111 65.74389
+##
+## $`Total within-cluster sum of squares`
+## [1] 79.77355
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.1582809
+The automatic zoning procedure (AZP) was initially outlined in Openshaw (1977) as a way to address some of the consequences of the modifiable areal unit problem (MAUP). In essence, it consists of a heuristic to find the best set of combinations of contiguous spatial units into p regions, minimizing the within-sum of squares as a criterion of homogeneity. The number of regions needs to be specified beforehand, as in most other clustering methods considered so far.
+rgeoda
provides three different heuristic algorithms to find an optimal solution for AZP:
The original AZP heuristic is a local optimization procedure that cycles through a series of possible swaps between spatial units at the boundary of a set of regions. The process starts with an initial feasible solution, i.e., a grouping of n spatial units into p contiguous regions. This initial solution can be constructed in several different ways. The initial solution must satisfy the contiguity constraints. For example, this can be accomplished by growing a set of contiguous regions from p randomly selected seed units by adding neighboring locations until the contiguity constraint can no longer be met.
+
+azp_clusters <- azp_greedy(5, queen_w, data)
+azp_clusters
## $Clusters
+## [1] 5 2 3 1 1 1 2 1 2 1 1 1 2 1 4 4 3 4 2 3 3 1 2 1 2 2 3 1 1 1 1 1 3 3 3 1 2 1
+## [39] 2 3 1 3 2 1 1 1 3 3 2 2 3 2 2 3 2 3 2 2 3 2 1 1 1 1 2 2 1 2 3 3 2 2 2 2 4 2
+## [77] 1 1 1 1 4 4 4 2 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 47.20703 60.10165 32.71213 57.69760 59.41673 65.49840
+##
+## $`Total within-cluster sum of squares`
+## [1] 181.3665
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.3598541
+To call AZP simulate annealing algorithm, one needs to specify cooling_rate (default: 0.85):
+
+azp_clusters <- azp_sa(5, queen_w, data, cooling_rate = 0.85)
+azp_clusters
## $Clusters
+## [1] 5 2 5 1 1 1 2 1 2 1 1 1 3 5 3 3 4 3 2 3 5 1 2 1 2 2 3 1 1 1 1 1 3 4 4 1 2 1
+## [39] 4 5 5 3 2 1 1 1 4 3 2 2 4 2 2 3 2 4 2 2 4 2 5 1 1 1 2 2 1 2 5 4 2 2 2 2 3 2
+## [77] 1 1 1 1 3 3 3 2 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 55.44537 44.49166 31.26639 44.79846 61.49413 54.25130
+##
+## $`Total within-cluster sum of squares`
+## [1] 212.2527
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.4211363
+To call AZP Tabu search algorithm, one needs to specify tabu_length (deafult: 10) , or conv_tabu (default: 10):
+
+azp_clusters <- azp_tabu(5, queen_w, data, tabu_length = 10, conv_tabu = 10)
+azp_clusters
## $Clusters
+## [1] 4 1 2 3 3 3 1 3 1 3 3 3 2 4 2 2 2 2 1 2 4 2 1 3 1 1 2 3 3 3 2 3 2 2 2 3 1 2
+## [39] 2 4 4 2 1 3 2 3 2 2 1 1 2 1 1 2 1 2 1 1 2 1 4 3 3 3 1 1 3 1 4 2 1 1 1 1 5 1
+## [77] 3 3 3 3 5 5 2 1 1
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 52.20796 39.86439 30.75532 54.95106 54.00440 59.41931
+##
+## $`Total within-cluster sum of squares`
+## [1] 212.7976
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.4222174
+NOTE: the AZP algorithm is very sensitive to the initial positions for constructing final solutions. Therefore, the random seed, which is used to determine the initial positions, could be used to execute several rounds of max-p algorithms for sensitive analysis.
+The so-called max-p regions model (outlined in Duque, Anselin, and Rey 2012) uses a different approach and considers the regionalization problem as an application of integer programming. Besides, the number of regions is determined endogenously.
+The algorithm itself consists of a search process that starts with an initial feasible solution and iteratively improves upon it while maintaining contiguity among the elements of each cluster. rgeoda
provides three different heuristic algorithms to find an optimal solution for max-p:
Unlike SKATER and REDCAP that one can specify the number of clusters as an input parameter, max-p doesn’t allow to specify the number of clusters explicitly, but a constrained variable and the minimum bounding value that each cluster should reach that are used to find an optimized number of clusters.
+For example, to use the greedy
algorithm in maxp function with the same dataset and weights as above to find optimal clusters using max-p:
First, we need to specify, for example, every cluster must have population >= 3236.67 thousand people:
+
+bound_vals <- guerry['Pop1831']
+min_bound <- 3236.67 # 10% of Pop1831
Then, we can call the max-p function with the “greedy” algorithm, the bound values, and minimum bound value:
+
+maxp_clusters <- maxp_greedy(queen_w, data, bound_vals, min_bound)
+maxp_clusters
## $Clusters
+## [1] 4 8 6 3 4 3 8 1 2 1 1 3 7 1 6 5 6 6 4 5 6 6 4 3 2 2 5 3 1 1 1 3 5 7 7 4 4 1
+## [39] 7 3 6 5 2 1 6 3 7 7 2 4 7 8 8 5 8 6 2 8 7 2 6 1 1 1 8 8 4 4 3 7 2 2 2 2 5 2
+## [77] 1 1 3 3 5 5 5 4 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 58.53340 44.29870 26.78835 50.67614 50.07543 46.84457
+##
+## $`Total within-cluster sum of squares`
+## [1] 226.7834
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.4499671
+Note: the results of max-p may be different with GeoDa desktop software, it is caused by the different implementation of boost::unordered_map in version 1.58 (used in GeoDa) and version 1.75 (used in rgeoda via BH package). The keys in boost::unordered_map are not ordered and have different orders in the two Boost versions we used. This involves a different mechanism of randomness in max-p algorithm when picking which area or region to process. Therefore, the results might be slightly different. This is normal and shows the sensitiveness of the max-p algorithm: see https://geodacenter.github.io/workbook/9d_spatial4/lab9d.html#max-p-region-problem for more about sensitivy study of max-p algorithm.
+
+If you want to replicate the identical results as in GeoDa software v1.18.0, please install BH == 1.58.0-1 and build/install rgeoda from source using: devtools::install_github("lixun910/rgeoda")
+To use tabu search
algorithm in maxp function, we can specify the parameters of tabu_length and conv_tabu:
+maxp_tabu_clusters <- maxp_tabu(queen_w, data, bound_vals, min_bound, tabu_length=10, conv_tabu=10)
+maxp_tabu_clusters
## $Clusters
+## [1] 6 2 6 1 1 6 2 1 3 1 1 1 8 6 4 4 5 4 2 7 6 4 3 1 8 8 7 1 1 1 4 1 7 4 5 1 2 4
+## [39] 5 6 6 7 8 1 4 1 5 5 3 2 5 3 3 7 3 5 2 2 5 2 6 1 1 1 3 3 1 3 6 5 8 8 2 8 7 2
+## [77] 1 1 1 1 7 7 4 3 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 41.67030 38.07925 26.22669 52.73867 44.51344 54.13078
+##
+## $`Total within-cluster sum of squares`
+## [1] 246.6409
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.4893668
+To apply simulated annealing
algorithm in maxp function with the parameter of cooling rate:
+maxp_sa_clusters <- maxp_sa(queen_w, data, bound_vals, min_bound, cooling_rate=0.85, sa_maxit=1)
+maxp_sa_clusters
## $Clusters
+## [1] 2 8 5 2 2 4 8 3 1 3 4 2 1 3 5 6 5 5 2 6 5 5 1 2 1 7 6 4 3 3 5 4 6 7 7 2 2 5
+## [39] 7 4 3 6 1 3 3 4 7 7 1 2 7 1 1 6 1 5 8 8 7 8 5 3 3 3 1 1 2 1 4 7 1 1 1 1 6 8
+## [77] 4 4 2 4 6 6 6 1 2
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 49.54630 52.71528 31.38930 47.57064 44.96762 46.70911
+##
+## $`Total within-cluster sum of squares`
+## [1] 231.1018
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.4585352
+We can also increase the number of iterations for local search process by specifying the parameter iterations
(default value is 99):
+maxp_clusters <- maxp_greedy(queen_w, data, bound_vals, min_bound, iterations=199)
+maxp_clusters
## $Clusters
+## [1] 2 7 4 2 2 2 7 1 5 1 1 2 8 1 4 6 4 4 7 6 4 4 5 2 8 8 6 2 1 1 1 2 6 4 3 2 7 1
+## [39] 3 4 4 6 3 1 1 2 3 3 5 5 3 5 7 6 5 3 7 7 3 8 4 1 1 1 5 5 3 5 3 3 8 8 7 8 6 8
+## [77] 1 1 2 2 6 6 6 5 7
+##
+## $`Total sum of squares`
+## [1] 504
+##
+## $`Within-cluster sum of squares`
+## [1] 50.45471 42.41705 23.35407 52.46201 47.80935 46.88761
+##
+## $`Total within-cluster sum of squares`
+## [1] 240.6152
+##
+## $`The ratio of between to total sum of squares`
+## [1] 0.4774111
+NOTE: the max-p algorithm is very sensitive to the initial positions for constructing final solutions. Therefore, the random seed, which is used to determine the initial positions, could be used to execute several rounds of max-p algorithms for sensitive analysis.
+For exploratory spatial data analysis (ESDA), rgeoa provides some utility functions to allow users to easily work with sf to visualize the results and do exploratory spatial data analysis.
+sf
packageThe sf package has been popular tool to handle geospatial data. It is a good substitue of sp package which will be deprecated soon.
+For example, we can simply call plot() function to render the first 9 chorepleth maps using the frist 9 variables in the dataset:
+
+plot(guerry)
## Warning: plotting the first 9 out of 30 attributes; use max.plot = 30 to plot
+## all
+
+Now, with the sf object guerry
, you can call rgeoda’s spatial analysis functions. For example, to examine the local Moran statistics of variable “crm_prs” (Population per Crime against persons):
+queen_w <- queen_weights(guerry)
+lisa <- local_moran(queen_w, guerry['Crm_prs'])
Note: rgeoda uses wkb, which is a binary representation of geometries, to exchange data between sf and libgeoda in memory.
+With the LISA results, we can make a local moran cluster map:
+
+lisa_colors <- lisa_colors(lisa)
+lisa_labels <- lisa_labels(lisa)
+lisa_clusters <- lisa_clusters(lisa)
+
+plot(st_geometry(guerry),
+ col=sapply(lisa_clusters, function(x){return(lisa_colors[[x+1]])}),
+ border = "#333333", lwd=0.2)
+title(main = "Local Moran Map of Crm_prs")
+legend('bottomleft', legend = lisa_labels, fill = lisa_colors, border = "#eeeeee")
In the above code, we use th values of cluster indicators from rgeoda
’s LISA
object are used to make the LISA map. We can save the clusters back to the original sf
data.frame:
+guerry['moran_cluster'] <- lisa_clusters
Checking the values of the cluster indicators, we will see they are integer numbers 0 (not significant), 1 (high-high cluster), 2 (low-low cluster), 3 (low-high cluster), 4 (high-low cluster), 5 (neighborless/island), 6 (undefined):
+
+lisa_clusters
## [1] 0 1 1 0 0 2 0 2 0 2 2 0 0 2 0 0 1 0 0 0 0 0 0 2 0 0 0 2 2 0 0 2 1 0 3 0 0 0
+## [39] 0 0 0 0 0 0 0 2 0 0 3 0 1 0 0 0 0 0 1 0 0 1 0 0 0 2 0 0 0 0 1 1 0 0 0 0 0 0
+## [77] 2 2 0 2 0 0 0 0 0
+To create a significance map that is associated with the local Moran map, we can do the same as making the local moran cluster map using the results from lisa_pvalues():
+
+lisa_p <- lisa_pvalues(lisa)
+p_labels <- c("Not significant", "p <= 0.05", "p <= 0.01", "p <= 0.001")
+p_colors <- c("#eeeeee", "#84f576", "#53c53c", "#348124")
+plot(st_geometry(guerry),
+ col=sapply(lisa_p, function(x){
+ if (x <= 0.001) return(p_colors[4])
+ else if (x <= 0.01) return(p_colors[3])
+ else if (x <= 0.05) return (p_colors[2])
+ else return(p_colors[1])
+ }),
+ border = "#333333", lwd=0.2)
+title(main = "Local Moran Map of Crm_prs")
+legend('bottomleft', legend = p_labels, fill = p_colors, border = "#eeeeee")
rgeoda is a R package for spatial data analysis based on libgeoda and GeoDa. It provides spatial data analysis functionalities including Exploratory Spatial Data Analysis, Spatial Cluster Detection and Clustering Analysis, Regionalization, etc. based on the C++ source code of GeoDa, which is an open-source software tool that serves as an introduction to spatial data analysis. The GeoDa software and its documentation are available at https://geodacenter.github.io.
+The rgeoda site is built using pkgdown: https://geodacenter.github.io/rgeoda
+
+install.packages("rgeoda")
+library(sf)
+library(rgeoda)
+
+guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
+guerry <- st_read(guerry_path)
+
+w <- queen_weights(guerry)
+lisa <- local_moran(w, guerry['Crm_prs'])
+clusters <- skater(4, w, guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')])
In R console, one can use devtools to install rgeoda from its source package:
+
+devtools::install_github("geodacenter/rgeoda")
For Mac users, the “Xcode Command Line Tools” need to be installed for installing rgeoda. It is a free software provided by Apple, which can be installed by using the following command in a terminal:
+xcode-select --install
+Note that the Xcode tools are not automatically updated when a new version of Xcode is installed. In order to make sure you have the latest version, use:
+sudo rm -rf /Library/Developer/CommandLineTools
+xcode-select --install
+In order to make sure to have the correct C++ compiler for R 4.0 and later, follow the instructions on https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/.
+On Windows, the Rtools
needs to be installed first. https://cran.r-project.org/bin/windows/Rtools/
A LISA-class that wrappers the statistics of LISA computation
+gda_lisa
An object of GeoDaLISA
p_vals
The pseudo-p values of significance of LISA computation
c_vals
The cluster indicators of LISA computation
lisa_vals
The local spatial autocorrelation values of LISA computation
nn_vals
The number of neighbors of every observations in LISA +computation
labels
The cluster labels of LISA
colors
The cluster colors (HEX format) of LISA
GetBO(current_p)
Get the Bonferroni bound value
GetClusterIndicators()
Get the local cluster indicators returned from LISA computation.
GetColors()
Get the cluster colors of LISA computation.
GetFDR(current_p)
Get the False Discovery Rate value
GetLISAValues()
Get the local spatial autocorrelation values returned from LISA +computation.
GetLabels()
Get the cluster labels of LISA computation.
GetLocalSignificanceValues()
Get the local pseudo-p values of significance returned from LISA +computation.
GetNumNeighbors()
Get the number of neighbors of every observations in LISA computation.
Run()
Call to run LISA computation
SetPermutations(num_perm)
Set the number of permutations for the LISA computation
SetSignificanceCutoff(cutoff)
Set the cutoff value of significance values
SetThreads(num_threads)
Set the number of CPU threads for the LISA computation
initialize(lisa_obj)
Constructor with a LISA object (internally used)
A wrapper class for p_GeoDaWeight class
+gda_w
An object of p_GeoDaWeight-class
is_symmetric
If weights matrix is symmetric
sparsity
Sparsity of weights matrix
min_neighbors
Minimum number of neighbors
max_neighbors
Maximum number of neighbors
num_obs
Number of observations
mean_neighbors
Mean number of neighbors
median_neighbors
Median number of neighbors
has_isolates
If the weights matrix has any isolates
GetNeighborWeights(idx)
Get weights values of neighbors for idx-th observation, +idx starts from 0
GetNeighbors(idx)
Get neighbors for idx-th observation, idx starts from 0
GetPointer()
Get the C++ object pointer (internally used)
GetSparsity()
Get sparsity computed from weights matrix
HasIsolates()
Check if weights matrix has isolates, or if any observation has no +neighbors
IsSymmetric()
Check if weights matrix is symmetric
SaveToFile(out_path, layer_name, id_name, id_values)
Save current spatial weights to a file.
+out_path: The path of an output weights file
+layer_name : The name of the layer of input dataset
+id_name : The id name (or field name), which is an associated column
+contains unique values, that makes sure that the weights are connected
+to the correct observations in the data table.
+id_values : The tuple of values of selected id_name (column/field)
SetNeighbors(idx, nbrs)
Set neighbors for one observation
SetNeighborsAndWeights(idx, nbrs, nbr_w)
Set neighbors with weights values for one observation
SpatialLag(values)
Compute spatial lag values for values of selected variable
Update(updateStats = TRUE)
Update the weights meta data
initialize(o_gda_w)
Constructor with a GeoDaWeight object (internally used)
Override the as.data.frame function for rgeoda instance
+# S3 method for geoda +as.data.frame(x, row.names = NULL, optional = FALSE, ...)+ +
x | +A rgeoda object |
+
---|---|
row.names | +NULL or a character vector giving the row names for the data +frame. Missing values are not allowed. |
+
optional | +optional parameters |
+
... | +other arguments passed to methods |
+
A data.frame object
+ +R/sf_geoda.R
+ as.geoda.Rd
Create an instance of geoda-class from an 'sf' object returned +from 'st_read()' function, +or a 'sp' object returned from 'readOGR()' function. +NOTE: The table content is NOT used to create an instance of geoda-class.
+as.geoda(obj, with_table = TRUE)+ +
obj | +An instance of 'sf' or 'sp' object |
+
---|---|
with_table | +A boolean flag indicates if table is copied from sf object +to create geoda object. Default is TRUE |
+
An instance of geoda-class
+ +Convert a GeoDa spatial weights object to a Matrix object
+# S3 method for Weight +as.matrix(x, rownames = NULL, rownames.value = NULL, ...)+ +
x | +A weights object |
+
---|---|
rownames | +optional, a single column name or column number to use as the +rownames in the returned matrix. If TRUE the key of the data.table will be +used if it is a single column, otherwise the first column in the data.table +will be used. |
+
rownames.value | +optional, a vector of values to be used as the rownames +in the returned matrix. It must be the same length as nrow(x). |
+
... | +Required to be present because the generic `as.matrix` generic +has it. Arguments here are not currently used or passed on by this method. |
+
A matrix object
+ +The automatic zoning procedure (AZP) was initially outlined in Openshaw (1977) as a way to address some of the consequences of the modifiable areal unit problem (MAUP). In essence, it consists of a heuristic to find the best set of combinations of contiguous spatial units into p regions, minimizing the within sum of squares as a criterion of homogeneity. The number of regions needs to be specified beforehand.
+azp_greedy( + p, + w, + df, + bound_variable = data.frame(), + min_bound = 0, + inits = 0, + initial_regions = vector("numeric"), + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789 +)+ +
p | +The number of spatially constrained clusters |
+
---|---|
w | +An instance of Weight class |
+
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
bound_variable | +(optional) A data frame with selected bound variabl |
+
min_bound | +(optional) A minimum bound value that applies to all clusters |
+
inits | +(optional) The number of construction re-runs, which is for ARiSeL "automatic regionalization with initial seed location" |
+
initial_regions | +(optional) The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(optional) The seed for random number generator. Defaults to 123456789. |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +azp_clusters <- azp_greedy(5, queen_w, data) +azp_clusters +} +
The automatic zoning procedure (AZP) was initially outlined in Openshaw (1977) as a way to address some of the consequences of the modifiable areal unit problem (MAUP). In essence, it consists of a heuristic to find the best set of combinations of contiguous spatial units into p regions, minimizing the within sum of squares as a criterion of homogeneity. The number of regions needs to be specified beforehand.
+azp_sa( + p, + w, + df, + cooling_rate, + sa_maxit = 1, + bound_variable = data.frame(), + min_bound = 0, + inits = 0, + initial_regions = vector("numeric"), + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789 +)+ +
p | +The number of spatially constrained clusters |
+
---|---|
w | +An instance of Weight class |
+
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
cooling_rate | +The cooling rate of a simulated annealing algorithm. Defaults to 0.85 |
+
sa_maxit | +(optional): The number of iterations of simulated annealing. Defaults to 1 |
+
bound_variable | +(optional) A data frame with selected bound variabl |
+
min_bound | +(optional) A minimum bound value that applies to all clusters |
+
inits | +(optional) The number of construction re-runs, which is for ARiSeL "automatic regionalization with initial seed location" |
+
initial_regions | +(optional) The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(optional) The seed for random number generator. Defaults to 123456789. |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +azp_clusters <- azp_sa(5, queen_w, data, cooling_rate = 0.85) +azp_clusters +} +
The automatic zoning procedure (AZP) was initially outlined in Openshaw (1977) as a way to address some of the consequences of the modifiable areal unit problem (MAUP). In essence, it consists of a heuristic to find the best set of combinations of contiguous spatial units into p regions, minimizing the within sum of squares as a criterion of homogeneity. The number of regions needs to be specified beforehand.
+azp_tabu( + p, + w, + df, + tabu_length = 10, + conv_tabu = 10, + bound_variable = data.frame(), + min_bound = 0, + inits = 0, + initial_regions = vector("numeric"), + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789 +)+ +
p | +The number of spatially constrained clusters |
+
---|---|
w | +An instance of Weight class |
+
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
tabu_length | +The length of a tabu search heuristic of tabu algorithm. e.g. 10. |
+
conv_tabu | +(optional): The number of non-improving moves. Defaults to 10. |
+
bound_variable | +(optional) A data frame with selected bound variabl |
+
min_bound | +(optional) A minimum bound value that applies to all clusters |
+
inits | +(optional) The number of construction re-runs, which is for ARiSeL "automatic regionalization with initial seed location" |
+
initial_regions | +(optional) The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(optional) The seed for random number generator. Defaults to 123456789. |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +azp_clusters <- azp_tabu(5, queen_w, data, tabu_length=10, conv_tabu=10) +azp_clusters +} +
Create a distance-based weights
+distance_weights( + sf_obj, + dist_thres, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
dist_thres | +A positive numeric value of distance threshold |
+
power | +(optional) The power (or exponent) of a number indicates how +many times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++#>guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIdist_thres <- min_distthreshold(guerry) +dist_w <- distance_weights(guerry, dist_thres) +summary(dist_w) +#> name value +#> 1 number of observations: 85 +#> 2 is symmetric: TRUE +#> 3 sparsity: 0.0434602076124567 +#> 4 # min neighbors: 1 +#> 5 # max neighbors: 7 +#> 6 # mean neighbors: 3.69411764705882 +#> 7 # median neighbors: 4 +#> 8 has isolates: FALSE
The function to compute EB Rate from an event variable and a +base variable.
+eb_rates(df)+ +
df | +A data frame with two selected variable: one is "event", anothor is +"base" variable. E.g. guerry[c("hr60", "po60")] |
+
---|
A data.frame with two columns "EB Rate" and "IsNull".
+ ++
R/weights.R
+ gda_distance_weights.Rd
Create a distance-based weights
+gda_distance_weights( + geoda_obj, + dist_thres, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
geoda_obj | +An instance of geoda-class |
+
---|---|
dist_thres | +A positive numeric value of distance threshold |
+
power | +(optional) The power (or exponent) of a number indicates how +many times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +dist_thres <- gda_min_distthreshold(guerry) +dist_w <- gda_distance_weights(guerry, dist_thres) +summary(dist_w) +} +
R/weights.R
+ gda_kernel_knn_weights.Rd
Create a kernel weights by specifying k-nearest neighbors and a +kernel method
+gda_kernel_knn_weights( + geoda_obj, + k, + kernel_method, + adaptive_bandwidth = TRUE, + use_kernel_diagonals = FALSE, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
geoda_obj | +An instance of geoda |
+
---|---|
k | +a positive integer number for k-nearest neighbors |
+
kernel_method | +a string value, which has to be one of 'triangular', +'uniform', 'epanechnikov', 'quartic', 'gaussian' |
+
adaptive_bandwidth | +(optional) TRUE (default) or FALSE: TRUE use +adaptive bandwidth calculated using distance of k-nearest neithbors, +FALSE use max distance of all observation to their k-nearest neighbors |
+
use_kernel_diagonals | +(optional) FALSE (default) or TRUE, apply kernel +on the diagonal of weights matrix |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +adptkernel_w = gda_kernel_knn_weights(guerry, 6, "uniform") +summary(adptkernel_w) +} +
R/weights.R
+ gda_kernel_weights.Rd
Create a kernel weights by specifying a bandwidth and a kernel +method
+gda_kernel_weights( + geoda_obj, + bandwidth, + kernel_method, + use_kernel_diagonals = FALSE, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
geoda_obj | +An instance of geoda-class |
+
---|---|
bandwidth | +A positive numeric value of bandwidth |
+
kernel_method | +a string value, which has to be one of 'triangular', +'uniform', 'epanechnikov', 'quartic', 'gaussian' |
+
use_kernel_diagonals | +(optional) FALSE (default) or TRUE, apply kernel +on the diagonal of weights matrix |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +bandwidth <- gda_min_distthreshold(guerry) +kernel_w <- gda_kernel_weights(guerry, bandwidth, kernel_method = "uniform") +summary(kernel_w) +} +
R/weights.R
+ gda_knn_weights.Rd
Create a k-nearest neighbors based spatial weights
+gda_knn_weights( + geoda_obj, + k, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
geoda_obj | +An instance of geoda |
+
---|---|
k | +a positive integer number for k-nearest neighbors |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit +from mile to km. |
+
An instance of Weight-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +knn6_w <- gda_knn_weights(guerry, 6) +summary(knn6_w) +} +
R/weights.R
+ gda_min_distthreshold.Rd
Get minimum threshold of distance that makes sure each +observation has at least one neighbor
+gda_min_distthreshold(geoda_obj, is_arc = FALSE, is_mile = TRUE)+ +
geoda_obj | +An instance of geoda-class |
+
---|---|
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, if 'is_arc' option is +TRUE, then 'is_mile' will set distance unit to 'mile' or 'km'. |
+
A numeric value of minimum threshold of distance
+ +R/weights.R
+ gda_queen_weights.Rd
Create a Queen contiguity weights with options of "order", +"include lower order" and "precision threshold"
+gda_queen_weights( + geoda_obj, + order = 1, + include_lower_order = FALSE, + precision_threshold = 0 +)+ +
geoda_obj | +An object of [geoda] class |
+
---|---|
order | +(Optional) Order of contiguity |
+
include_lower_order | +(Optional) Whether or not the lower order +neighbors should be included in the weights structure |
+
precision_threshold | +(Optional) The precision of the underlying shape +file is insufficient to allow for an exact match of coordinates to determine +which polygons are neighbors |
+
An instance of Weight-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +queen_w <- gda_queen_weights(guerry) +summary(queen_w) +} +
R/weights.R
+ gda_rook_weights.Rd
Create a Rook contiguity weights with options of "order", +"include lower order" and "precision threshold"
+gda_rook_weights( + geoda_obj, + order = 1, + include_lower_order = FALSE, + precision_threshold = 0 +)+ +
geoda_obj | +An object of [geoda] class |
+
---|---|
order | +(Optional) Order of contiguity |
+
include_lower_order | +(Optional) Whether or not the lower order +neighbors should be included in the weights structure |
+
precision_threshold | +(Optional) The precision of the underlying shape +file is insufficient to allow for an exact match of coordinates to determine + which polygons are neighbors |
+
An instance of Weight-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +rook_w <- gda_rook_weights(guerry) +summary(rook_w) +} +
'geoda' is a RefClass that wraps the C++ GeoDa class +(via p_GeoDa defines in rgeoda.R)
+gda
The pointer to the instance of p_GeoDa-class
map_type
The map type, could be either Point or Polygon
n_cols
The number of columns
n_obs
The number of observations
field_names
A string vector of field names
field_types
A string vector of field types (integer, real, string)
GetFieldNames(...)
Get the field names of all columns
GetFieldTypes(...)
Get the field types (integer, real, string) of all columns
GetIntegerCol(col_name)
Get the integer values from a column
GetMapType(...)
Get the map type
GetNumCols(...)
Get the number of columns
GetNumObs(...)
Get the number of observations
GetPointer()
Get the C++ object pointer (internally used)
GetRealCol(col_name)
Get the real values from a column
GetUndefinedVals(col_name)
Get the undefined flags from a column
initialize(o_gda)
Constructor with a geoda object (internally used)
R/read_geoda.R
+ geoda_open.Rd
Create an instance of geoda-class by reading from an ESRI +Shapefile dataset.
+geoda_open(ds_path)+ +
ds_path | +(character) The path of the spatial dataset |
+
---|
An instance of geoda-class
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- geoda_open(guerry_path) +guerry_df <- as.data.frame(guerry) # access as a data.frame +head(guerry_df) +} +
Get neighbors for idx-th observation, idx starts from 1
+get_neighbors(gda_w, idx)+ +
gda_w | +A Weight object |
+
---|---|
idx | +A value indicates idx-th observation, idx start from 1 |
+
A numeric vector of the neighbor indices, which start from 1
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +nbrs <- get_neighbors(queen_w, idx = 1) +cat("\nNeighbors of the 1-st observation are:", nbrs) +} +
R/weights.R
+ get_neighbors_weights.Rd
Get the associated weights values of neighbors for idx-th +observation
+get_neighbors_weights(gda_w, idx)+ +
gda_w | +A Weight object |
+
---|---|
idx | +A value indicates idx-th observation, idx start from 1 |
+
A numeric vector of the neighbor indices, which start from 1
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +nbrs <- get_neighbors_weights(queen_w, idx = 1) +cat("\nNeighbors of the 1-st observation are:", nbrs) +} +
Check if weights matrix has isolates, or if any observation has +no neighbors
+has_isolates(gda_w)+ +
gda_w | +A Weight object |
+
---|
A boolean value indicates if weights matrix is symmetric
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +has_isolates(queen_w) +} +
Hinge15 breaks data into 6 groups like box plot groups +(Lower outlier, < 25
+hinge15_breaks(df)+ +
df | +A data frame with selected variable. E.g. guerry["Crm_prs"] |
+
---|
A vector of numeric values of computed breaks
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIhinge15_breaks(guerry['Crm_prs']) +#> [1] -2356.5 14790.0 18785.0 26221.0 43367.5
Hinge30 breaks data into 6 groups like box plot groups +(Lower outlier, < 25
+hinge30_breaks(df)+ +
df | +A data frame with selected variable. E.g. guerry["Crm_prs"] |
+
---|
A vector of numeric values of computed breaks
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIhinge30_breaks(guerry['Crm_prs']) +#> [1] -19503 14790 18785 26221 60514
Check if weights matrix is symmetric
+is_symmetric(gda_w)+ +
gda_w | +A Weight object |
+
---|
A boolean value indicates if weights matrix is symmetric
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +is_symmetric(queen_w) +} +
Join count ratio is the join counts, the number of times a category is surrounded +by neighbors of the same category, over the total number of neighbors after converting +each category to a dummy variable.
+join_count_ratio(clusters, w)+ +
clusters | +A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) |
+
---|---|
w | +An instance of Weight class |
+
A data.frame with names "Cluster", "N", "Neighbors", "Join Count", "Ratio"
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +clusters <- skater(5, queen_w, data) +results <- join_count_ratio(clusters, queen_w) +results +} +
Create a kernel weights by specifying k-nearest neighbors and a +kernel method
+kernel_knn_weights( + sf_obj, + k, + kernel_method, + adaptive_bandwidth = TRUE, + use_kernel_diagonals = FALSE, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
k | +a positive integer number for k-nearest neighbors |
+
kernel_method | +a string value, which has to be one of 'triangular', +'uniform', 'epanechnikov', 'quartic', 'gaussian' |
+
adaptive_bandwidth | +(optional) TRUE (default) or FALSE: TRUE use +adaptive bandwidth calculated using distance of k-nearest neithbors, +FALSE use max distance of all observation to their k-nearest neighbors |
+
use_kernel_diagonals | +(optional) FALSE (default) or TRUE, apply kernel +on the diagonal of weights matrix |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone II#> name value +#> 1 number of observations: 85 +#> 2 is symmetric: FALSE +#> 3 sparsity: 0.0705882352941176 +#> 4 # min neighbors: 6 +#> 5 # max neighbors: 6 +#> 6 # mean neighbors: 6 +#> 7 # median neighbors: 6 +#> 8 has isolates: FALSE
Create a kernel weights by specifying a bandwidth and a kernel +method
+kernel_weights( + sf_obj, + bandwidth, + kernel_method, + use_kernel_diagonals = FALSE, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
bandwidth | +A positive numeric value of bandwidth |
+
kernel_method | +a string value, which has to be one of 'triangular', +'uniform', 'epanechnikov', 'quartic', 'gaussian' |
+
use_kernel_diagonals | +(optional) FALSE (default) or TRUE, apply kernel +on the diagonal of weights matrix |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIbandwidth <- min_distthreshold(guerry) +kernel_w <- kernel_weights(guerry, bandwidth, kernel_method = "uniform") +summary(kernel_w) +#> name value +#> 1 number of observations: 85 +#> 2 is symmetric: FALSE +#> 3 sparsity: 0.0434602076124567 +#> 4 # min neighbors: 1 +#> 5 # max neighbors: 7 +#> 6 # mean neighbors: 3.69411764705882 +#> 7 # median neighbors: 4 +#> 8 has isolates: FALSE
Create a k-nearest neighbors based spatial weights
+knn_weights( + sf_obj, + k, + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
k | +a positive integer number for k-nearest neighbors |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
An instance of Weight-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone II#> name value +#> 1 number of observations: 85 +#> 2 is symmetric: FALSE +#> 3 sparsity: 0.0705882352941176 +#> 4 # min neighbors: 6 +#> 5 # max neighbors: 6 +#> 6 # mean neighbors: 6 +#> 7 # median neighbors: 6 +#> 8 has isolates: FALSE
Get Bonferroni bound value based on current LISA computation +and current significat p-value
+lisa_bo(gda_lisa, current_p)+ +
gda_lisa | +An instance of LISA object |
+
---|---|
current_p | +A value of current siginificant p-value |
+
A numeric value of Bonferroni bound
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +bo <- lisa_bo(lisa, 0.05) +bo +} +
Get the local cluster indicators returned from LISA computation.
+lisa_clusters(gda_lisa, cutoff = 0)+ +
gda_lisa | +An instance of LISA object |
+
---|---|
cutoff | +A value of cutoff for significance p-values to filter +not-significant clusters, default=0.0, means not used |
+
A numeric vector of LISA cluster indicator
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +clsts <- lisa_clusters(lisa) +clsts +} +
Get the cluster colors of LISA computation.
+lisa_colors(gda_lisa)+ +
gda_lisa | +An instance of LISA object |
+
---|
A string vector of cluster colors
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +clrs <- lisa_colors(lisa) +clrs +} +
Get False Discovery Rate value based on current LISA +computation and current significant p-value
+lisa_fdr(gda_lisa, current_p)+ +
gda_lisa | +An instance of LISA object |
+
---|---|
current_p | +A value of current siginificant p-value |
+
A numeric vector of False Discovery Rate
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +fdr <- lisa_fdr(lisa, 0.05) +fdr +} +
Get cluster labels of LISA computation.
+lisa_labels(gda_lisa)+ +
gda_lisa | +An instance of LISA object |
+
---|
A string vector of cluster labels
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +lbls <- lisa_labels(lisa) +lbls +} +
Get numbers of neighbors for all observations
+lisa_num_nbrs(gda_lisa)+ +
gda_lisa | +An instance of LISA object |
+
---|
A numeric vector of the number of neighbors
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +nn <- lisa_num_nbrs(lisa) +nn +} +
Get the local pseudo-p values of significance returned from +LISA computation.
+lisa_pvalues(gda_lisa)+ +
gda_lisa | +An instance of LISA object |
+
---|
A numeric vector of pseudo-p values of local spatial autocorrelation
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +pvals <- lisa_pvalues(lisa) +pvals +} +
Get the local spatial autocorrelation values returned from +LISA computation
+lisa_values(gda_lisa)+ +
gda_lisa | +An instance of LISA object |
+
---|
A numeric vector of local spatial autocorrelation
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +lms <- lisa_values(lisa) +lms +} +
The function to apply local Bivariate Join Count statistics
+local_bijoincount( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with two selected variable. +E.g. guerry[c("TopCrm", "InvCrm")] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +guerry["InvCrm"] <- 1 - guerry[["TopCrm"]] +lisa <- local_bijoincount(queen_w, guerry[c("TopCrm", "InvCrm")]) +clsts<- lisa_clusters(lisa) +clsts +#> [1] 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 +#> [39] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 +#> [77] 0 0 0 0 0 0 0 0 0
The function to apply bivariate local Moran statistics
+local_bimoran( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with two selected variable. E.g. guerry[c('Crm_prs','Litercy')] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_bimoran(queen_w, guerry[c('Crm_prs','Litercy')]) +lms <- lisa_values(lisa) +lms +#> [1] 0.392663448 0.756136106 -0.878510576 -0.199244815 0.002743424 +#> [6] 0.576712627 2.817728780 0.773723986 -0.056577742 0.343779070 +#> [11] 0.815903467 0.299021035 -0.134732249 0.249750794 -0.469461086 +#> [16] 0.064196998 -0.239924063 0.657549123 1.214759133 -1.436363003 +#> [21] -3.302026863 -0.144006800 -1.773094173 -0.126845502 -0.467870578 +#> [26] 0.029766618 -1.880162375 0.267608761 0.080923262 0.034283662 +#> [31] -0.329523889 0.443178656 -0.273284234 -1.741226823 0.096138276 +#> [36] -0.021797060 0.642390841 0.002522658 -0.090383051 -0.743775399 +#> [41] 0.373595983 0.084599090 0.007510629 1.601252733 -0.243652571 +#> [46] 0.880011648 -0.899730263 -0.339928599 -0.811526079 1.167328497 +#> [51] -0.390766959 1.298159864 0.973775923 -0.504644610 -1.586580704 +#> [56] -0.186951322 0.471913418 0.690564555 0.155109018 0.132228208 +#> [61] 0.374974938 -0.013374715 0.028852768 1.366493286 -1.524816551 +#> [66] -2.266518385 0.067834623 0.539284687 0.028501681 -0.728115359 +#> [71] -0.749706749 -0.132827757 0.285757157 -0.893442637 0.109672584 +#> [76] 0.991750143 0.324093451 0.405301333 -0.063852236 0.157603591 +#> [81] -0.050301141 0.504772397 0.503896266 -0.252386250 -0.120728027
The function to apply Getis-Ord's local G statistics
+local_g( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variable only. E.g. guerry["Crm_prs"] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_g(queen_w, guerry["Crm_prs"]) +lms <- lisa_values(lisa) +lms +#> [1] 0.013819020 0.016115180 0.015686557 0.008553106 0.008955895 0.009334367 +#> [7] 0.013308440 0.008087712 0.013630374 0.006826279 0.007225672 0.007888609 +#> [13] 0.014730484 0.007001527 0.010762953 0.013095840 0.015949284 0.011504575 +#> [19] 0.014237186 0.015052499 0.013040676 0.010928335 0.014408469 0.008585361 +#> [25] 0.012514332 0.012786474 0.015575579 0.006456438 0.007994853 0.010233479 +#> [31] 0.012099990 0.007425918 0.015958393 0.013082465 0.015774323 0.011473900 +#> [37] 0.014776298 0.012273577 0.014570953 0.011606663 0.009521038 0.014304123 +#> [43] 0.012113381 0.009947183 0.010225083 0.007704696 0.013277240 0.014465491 +#> [49] 0.015265007 0.013283953 0.017400436 0.010150263 0.014656976 0.014929657 +#> [55] 0.011570904 0.014462851 0.016551293 0.012750574 0.014691353 0.018024844 +#> [61] 0.013968480 0.009633574 0.010687124 0.006455805 0.009648260 0.009217817 +#> [67] 0.015426694 0.013749051 0.015881541 0.014849044 0.010304059 0.015207027 +#> [73] 0.011328897 0.011698016 0.013013919 0.014743898 0.008330537 0.008660000 +#> [79] 0.007904004 0.007473691 0.012846891 0.013959041 0.014504177 0.011860750 +#> [85] 0.013923847
The function to apply local Geary statistics
+local_geary( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variable only. E.g. guerry["Crm_prs"] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_geary(queen_w, guerry["Crm_prs"]) +lms <- lisa_values(lisa) +lms +#> [1] 0.987725319 0.838345145 0.702801925 0.100402310 0.244977901 1.353310326 +#> [7] 3.623634688 1.536196129 0.861013426 0.725268063 0.571428163 0.001151306 +#> [13] 1.912088100 1.140906230 1.007912947 0.303683489 1.214635190 1.920535316 +#> [19] 1.610359805 0.446973853 5.156798989 0.919215466 3.107530093 0.230533117 +#> [25] 1.349244911 1.067920103 0.418377023 0.208541175 0.788634381 0.248262048 +#> [31] 0.364299667 0.136623420 0.708692856 3.108893756 1.981523756 0.922565985 +#> [37] 1.044173246 0.332298593 0.940330887 1.904654615 0.936064027 0.628686757 +#> [43] 0.390598000 2.689756388 1.278289774 0.793948353 1.683658729 1.301187948 +#> [49] 2.342671020 0.832225668 0.296215805 2.268056379 0.876680843 0.414701945 +#> [55] 1.979054136 0.561171709 0.378238452 1.849165484 1.207382342 1.157149740 +#> [61] 1.848857476 0.155525055 0.642205848 0.749419937 1.283938081 1.470817990 +#> [67] 1.263739703 0.964844188 0.338990398 1.924872243 0.659890869 2.135743520 +#> [73] 0.710008255 1.424041460 0.706001903 1.774528303 0.242422537 0.694451670 +#> [79] 0.001874143 0.055356016 0.428128655 2.024633135 2.497611820 1.048741881 +#> [85] 1.026405574
The function to apply Getis-Ord's local G* statistics
+local_gstar( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variable only. E.g. guerry["Crm_prs"] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_gstar(queen_w, guerry["Crm_prs"]) +lms <- lisa_values(lisa) +lms +#> [1] 0.014270222 0.015807678 0.015485705 0.008315062 0.009224485 0.008819945 +#> [7] 0.014961277 0.006953285 0.013152942 0.007173126 0.006898546 0.007845469 +#> [13] 0.013523322 0.007458852 0.011289400 0.012630942 0.015340884 0.011057393 +#> [19] 0.014597110 0.015314172 0.014050381 0.011030881 0.011811302 0.008413883 +#> [25] 0.011878745 0.012620950 0.016069618 0.006595570 0.008347058 0.010244797 +#> [31] 0.012382889 0.007406347 0.015364123 0.013727734 0.014876307 0.011307545 +#> [37] 0.014699000 0.011801400 0.014125401 0.012016630 0.009446979 0.013589716 +#> [43] 0.011794136 0.008991930 0.010579653 0.007148765 0.013539907 0.015023811 +#> [49] 0.014277631 0.013418811 0.017041222 0.011136808 0.014445073 0.014528019 +#> [55] 0.010046286 0.014325708 0.016157879 0.013120245 0.014767580 0.016391423 +#> [61] 0.013304133 0.009617901 0.009758617 0.005608600 0.009113563 0.007561237 +#> [67] 0.014419926 0.013501073 0.015755475 0.015328760 0.009552577 0.013986432 +#> [73] 0.011392248 0.011003674 0.012534774 0.015343101 0.008167716 0.008603441 +#> [79] 0.007818946 0.007497836 0.012606384 0.013122855 0.013681762 0.011639370 +#> [85] 0.013248815
The function to apply local Join Count statistics
+local_joincount( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variable only. E.g. guerry["Crm_prs"] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_joincount(queen_w, guerry['TopCrm']) +clsts<- lisa_clusters(lisa) +clsts +#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +#> [39] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 +#> [77] 0 0 0 0 0 0 0 0 0
The function to apply local Moran statistics
+local_moran( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with only selected variable. E.g. guerry["Crm_prs"] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_moran(queen_w, guerry["Crm_prs"]) +lms <- lisa_values(lisa) +lms +#> [1] 0.516120231 0.818275138 0.794086560 0.733161543 0.228467334 +#> [6] 0.829040272 0.615280448 1.627415446 -0.019525625 0.687081885 +#> [11] 1.707896579 0.821748275 -0.213568315 0.291316827 -0.184833414 +#> [16] -0.047198613 0.249972417 0.054411195 0.862095943 0.835368441 +#> [21] 0.538432168 -0.050446242 -0.681022658 0.678851849 -0.105369231 +#> [26] 0.038567922 1.116236578 1.168138859 0.162030880 0.069037225 +#> [31] 0.021522359 1.000255304 0.276308094 0.423159405 -0.101271972 +#> [36] 0.015647332 0.554846307 -0.027584417 0.111200075 -0.082994402 +#> [41] 0.281817532 -0.048962443 -0.015839144 0.830286100 -0.160743989 +#> [46] 1.597607483 0.396712769 0.862342357 -0.466396879 0.262343383 +#> [51] 1.424738721 -0.379247703 0.388066026 0.316231271 0.068795845 +#> [56] 0.405538158 0.977019076 0.202610060 0.714533504 0.601447598 +#> [61] -0.177594467 0.229608404 0.284505927 2.247991283 0.532787318 +#> [66] 1.039424040 -0.129846379 0.136565215 1.033851456 1.238521154 +#> [71] 0.296054062 -0.167632280 -0.041663121 0.036396148 -0.055081083 +#> [76] 1.166507105 0.773315084 0.523682291 0.851277285 0.884651013 +#> [81] 0.025497212 -0.326497225 -0.306819894 0.001277301 -0.125219240
The function to apply local Moran with EB Rate statistics. The +EB rate is first computed from "event" and "base" variables, and then used +in local moran statistics.
+local_moran_eb( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with two selected variable: one is "event", anothor +is "base" variable. E.g. guerry[c("hr60", "po60")] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the LISA +computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++if (FALSE) { +library(sf) +nat <- st_read("natregimes.shp") +nat_w <- queen_weights(nat) +lisa <- local_moran_eb(queen_w, guerry[c("hr60", "po60")]) +lms <- lisa_values(lisa) +lms +} +
The function to apply local Multivariate Geary statistics
+local_multigeary( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variables only. E.g. guerry["Crm_prs"] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants', +'Suicids')] +lisa <- local_multigeary(queen_w, data) +lms <- lisa_clusters(lisa) +lms +#> [1] 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 0 +#> [39] 1 0 1 2 1 1 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 0 1 +#> [77] 1 1 1 1 0 1 0 1 1
R/lisa.R
+ local_multijoincount.Rd
The function to apply (multivariate) colocation local Join Count + statistics
+local_multijoincount( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variables only. +E.g. guerry[c("TopCrm", "TopWealth", "TopLit")] |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the +LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_multijoincount(queen_w, +guerry[c('TopWealth','TopWealth', 'TopLit')]) +clsts <- lisa_clusters(lisa) +clsts +#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +#> [39] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +#> [77] 0 0 0 0 0 0 0 0 0
The function to apply multivariate quantile LISA statistics
+local_multiquantilelisa( + w, + df, + k, + q, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variables only. +E.g. guerry[c("TopCrm", "TopWealth", "TopLit")] |
+
k | +A vector of "k" values indicate the number of quantiles for each +variable. Value range e.g. [1, 10] |
+
q | +A vector of "q" values indicate which quantile or interval for each +variable used in local join count statistics. Value stars from 1. |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the LISA +computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_multiquantilelisa(queen_w, guerry[c("Crm_prp", "Litercy")], +k=c(4,4), q=c(1,1)) +clsts <- lisa_clusters(lisa) +clsts +#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +#> [39] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +#> [77] 0 0 0 0 0 0 0 0 0
The function to apply quantile LISA statistics
+local_quantilelisa( + w, + df, + k, + q, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +)+ +
w | +An instance of Weight object |
+
---|---|
df | +A data frame with selected variable only. E.g. guerry["Crm_prs"] |
+
k | +A value indicates the number of quantiles. Value range e.g. [1, 10] |
+
q | +A value indicates which quantile or interval used in local join +count statistics. Value stars from 1. |
+
permutations | +(optional) The number of permutations for the LISA +computation |
+
permutation_method | +(optional) The permutation method used for the LISA +computation. Options are 'complete', 'lookup'. Default is 'complete'. |
+
significance_cutoff | +(optional) A cutoff value for significance +p-values to filter not-significant clusters |
+
cpu_threads | +(optional) The number of cpu threads used for parallel +LISA computation |
+
seed | +(optional) The seed for random number generator |
+
An instance of LISA-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +lisa <- local_quantilelisa(queen_w, guerry["Crm_prs"], k=4, q=1) +clsts <- lisa_clusters(lisa) +clsts +#> [1] 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 +#> [39] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +#> [77] 0 0 1 1 0 0 0 0 0
Make spatially constrained clusters from spatially non-constrained clusters +using the contiguity information from the input weights
+make_spatial(clusters, w)+ +
clusters | +A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) |
+
---|---|
w | +An instance of Weight class |
+
A vector of categorical values (cluster classification)
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +clusters <- kmeans(5, data) +queen_w <- queen_weights(guerry) +results <- make_spatial(clusters, queen_w) +results +} +
Get the number of maximum neighbors of spatial weights
+max_neighbors(gda_w)+ +
gda_w | +A Weight object |
+
---|
The number of maximum neighbors of spatial weights
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +max_neighbors(queen_w) +} +
The max-p-region problem is a special case of constrained +clustering where a finite number of geographical areas are aggregated into +the maximum number of regions (max-p-regions), such that each region is +geographically connected and the clusters could maximize internal homogeneity.
+maxp_greedy( + w, + df, + bound_variable, + min_bound, + iterations = 99, + initial_regions = vector("numeric"), + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789, + cpu_threads = 6 +)+ +
w | +An instance of Weight class |
+
---|---|
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
bound_variable | +A numeric vector of selected bounding variable |
+
min_bound | +A minimum value that the sum value of bounding variable int each cluster should be greater than |
+
iterations | +(optional): The number of iterations of greedy algorithm. Defaults to 99. |
+
initial_regions | +(optional): The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(optional) The seed for random number generator. Defaults to 123456789. |
+
cpu_threads | +(optional) The number of cpu threads used for parallel computation |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +bound_variable <- guerry['Pop1831'] +min_bound <- 3236.67 # 10% of Pop1831 +maxp_clusters <- maxp_greedy(queen_w, data, bound_variable, min_bound, iterations=99) +maxp_clusters +} +
R/clustering.R
+ maxp_sa.Rd
The max-p-region problem is a special case of constrained +clustering where a finite number of geographical areas are aggregated into +the maximum number of regions (max-p-regions), such that each region is +geographically connected and the clusters could maximize internal homogeneity.
+maxp_sa( + w, + df, + bound_variable, + min_bound, + cooling_rate, + sa_maxit = 1, + iterations = 99, + initial_regions = vector("numeric"), + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789, + cpu_threads = 6 +)+ +
w | +An instance of Weight class |
+
---|---|
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
bound_variable | +A numeric vector of selected bounding variable |
+
min_bound | +A minimum value that the sum value of bounding variable int each cluster should be greater than |
+
cooling_rate | +The cooling rate of a simulated annealing algorithm. Defaults to 0.85 |
+
sa_maxit | +(optional): The number of iterations of simulated annealing. Defaults to 1 |
+
iterations | +(optional): The number of iterations of SA algorithm. Defaults to 99. |
+
initial_regions | +(optional): The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(optional) The seed for random number generator. Defaults to 123456789. |
+
cpu_threads | +(optional) The number of cpu threads used for parallel computation |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +bound_variable <- guerry['Pop1831'] +min_bound <- 3236.67 # 10% of Pop1831 +maxp_clusters <- maxp_sa(queen_w, data, bound_variable, min_bound, cooling_rate=0.85, sa_maxit=1) +maxp_clusters +} +
R/clustering.R
+ maxp_tabu.Rd
The max-p-region problem is a special case of constrained +clustering where a finite number of geographical areas are aggregated into +the maximum number of regions (max-p-regions), such that each region is +geographically connected and the clusters could maximize internal homogeneity.
+maxp_tabu( + w, + df, + bound_variable, + min_bound, + tabu_length = 10, + conv_tabu = 10, + iterations = 99, + initial_regions = vector("numeric"), + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789, + cpu_threads = 6 +)+ +
w | +An instance of Weight class |
+
---|---|
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
bound_variable | +A numeric vector of selected bounding variable |
+
min_bound | +A minimum value that the sum value of bounding variable int each cluster should be greater than |
+
tabu_length | +(optional): The length of a tabu search heuristic of tabu algorithm. Defaults to 10. |
+
conv_tabu | +(optional): The number of non-improving moves. Defaults to 10. |
+
iterations | +(optional): The number of iterations of Tabu algorithm. Defaults to 99. |
+
initial_regions | +(optional): The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(optional) The seed for random number generator. Defaults to 123456789. |
+
cpu_threads | +(optional) The number of cpu threads used for parallel computation |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +bound_variable <- guerry['Pop1831'] +min_bound <- 3236.67 # 10% of Pop1831 +maxp_clusters <- maxp_tabu(queen_w, data, bound_variable, min_bound, tabu_length=10, conv_tabu=10) +maxp_clusters +} +
Get the number of mean neighbors of spatial weights
+mean_neighbors(gda_w)+ +
gda_w | +A Weight object |
+
---|
The number of mean neighbors of spatial weights
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +mean_neighbors(queen_w) +} +
Get the number of median neighbors of spatial weights
+median_neighbors(gda_w)+ +
gda_w | +A Weight object |
+
---|
The number of median neighbors of spatial weights
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +median_neighbors(queen_w) +} +
R/weights.R
+ min_distthreshold.Rd
Get minimum threshold of distance that makes sure each +observation has at least one neighbor
+min_distthreshold(sf_obj, is_arc = FALSE, is_mile = TRUE)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations |
+
is_mile | +(optional) TRUE (default) or FALSE, if 'is_arc' option is +TRUE, then 'is_mile' will set distance unit to 'mile' or 'km'. |
+
A numeric value of minimum threshold of distance
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +dist_thres <- min_distthreshold(guerry) +dist_thres +} +
Get the number of minimum neighbors of spatial weights
+min_neighbors(gda_w)+ +
gda_w | +A Weight object |
+
---|
The number of minimum neighbors of spatial weights
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +min_neighbors(queen_w) +} +
Natural Breaks group data whose boundaries are set where there +are relatively big differences.
+natural_breaks(k, df)+ +
k | +A numeric value indicates how many breaks |
+
---|---|
df | +A data frame with selected variable. E.g. guerry["Crm_prs"] |
+
A vector of numeric values of computed breaks
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IInatural_breaks(k=5, guerry['Crm_prs']) +#> [1] 9474 16722 23316 29872
The local neighbor match test is to assess the extent of overlap + between k-nearest neighbors in geographical space and k-nearest neighbors in + multi-attribute space.
+neighbor_match_test( + df, + k, + scale_method = "standardize", + distance_method = "euclidean", + power = 1, + is_inverse = FALSE, + is_arc = FALSE, + is_mile = TRUE +)+ +
df | +A subset of sf object with selected variables. +E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
---|---|
k | +a positive integer number for k-nearest neighbors searching. |
+
scale_method | +(optional) One of the scaling methods 'raw', +'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply + on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The type of distance metrics used to +measure the distance between input data. Options are 'euclidean', 'manhattan'. Default is 'euclidean'. |
+
power | +(optional) The power (or exponent) of a number says how many +times to use the number in a multiplication. |
+
is_inverse | +(optional) FALSE (default) or TRUE, apply inverse on +distance value. |
+
is_arc | +(optional) FALSE (default) or TRUE, compute arc distance +between two observations. |
+
is_mile | +(optional) TRUE (default) or FALSE, convert distance unit from +mile to km. |
+
A data.frame with two columns "Cardinality" and "Probability".
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIdata <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +nbr_test <- neighbor_match_test(data, 6) +nbr_test +#> Cardinality Probability +#> 1 2 5.263800e-02 +#> 2 3 3.743147e-03 +#> 3 2 5.263800e-02 +#> 4 2 5.263800e-02 +#> 5 0 NA +#> 6 1 3.116170e-01 +#> 7 1 3.116170e-01 +#> 8 2 5.263800e-02 +#> 9 3 3.743147e-03 +#> 10 1 3.116170e-01 +#> 11 3 3.743147e-03 +#> 12 2 5.263800e-02 +#> 13 1 3.116170e-01 +#> 14 1 3.116170e-01 +#> 15 0 NA +#> 16 2 5.263800e-02 +#> 17 1 3.116170e-01 +#> 18 2 5.263800e-02 +#> 19 1 3.116170e-01 +#> 20 2 5.263800e-02 +#> 21 2 5.263800e-02 +#> 22 1 3.116170e-01 +#> 23 2 5.263800e-02 +#> 24 3 3.743147e-03 +#> 25 1 3.116170e-01 +#> 26 1 3.116170e-01 +#> 27 1 3.116170e-01 +#> 28 4 1.108168e-04 +#> 29 3 3.743147e-03 +#> 30 3 3.743147e-03 +#> 31 0 NA +#> 32 2 5.263800e-02 +#> 33 2 5.263800e-02 +#> 34 1 3.116170e-01 +#> 35 1 3.116170e-01 +#> 36 0 NA +#> 37 1 3.116170e-01 +#> 38 0 NA +#> 39 2 5.263800e-02 +#> 40 3 3.743147e-03 +#> 41 3 3.743147e-03 +#> 42 0 NA +#> 43 2 5.263800e-02 +#> 44 1 3.116170e-01 +#> 45 1 3.116170e-01 +#> 46 1 3.116170e-01 +#> 47 2 5.263800e-02 +#> 48 2 5.263800e-02 +#> 49 2 5.263800e-02 +#> 50 4 1.108168e-04 +#> 51 2 5.263800e-02 +#> 52 2 5.263800e-02 +#> 53 3 3.743147e-03 +#> 54 2 5.263800e-02 +#> 55 2 5.263800e-02 +#> 56 1 3.116170e-01 +#> 57 4 1.108168e-04 +#> 58 3 3.743147e-03 +#> 59 1 3.116170e-01 +#> 60 3 3.743147e-03 +#> 61 2 5.263800e-02 +#> 62 2 5.263800e-02 +#> 63 3 3.743147e-03 +#> 64 0 NA +#> 65 3 3.743147e-03 +#> 66 3 3.743147e-03 +#> 67 0 NA +#> 68 1 3.116170e-01 +#> 69 0 NA +#> 70 2 5.263800e-02 +#> 71 2 5.263800e-02 +#> 72 1 3.116170e-01 +#> 73 3 3.743147e-03 +#> 74 1 3.116170e-01 +#> 75 1 3.116170e-01 +#> 76 2 5.263800e-02 +#> 77 5 1.151344e-06 +#> 78 4 1.108168e-04 +#> 79 2 5.263800e-02 +#> 80 3 3.743147e-03 +#> 81 1 3.116170e-01 +#> 82 0 NA +#> 83 0 NA +#> 84 1 3.116170e-01 +#> 85 2 5.263800e-02
p_GeoDa class is a RefClass that wraps the C++ 'GeoDa' class. +See C++ functions in rcpp_rgeoda.cpp
+p_GeoDaTable class is a RefClass that wraps the C++ 'GeoDaTable' +class. +See C++ functions in rcpp_rgeoda.cpp
+p_GeoDaWeight class is a RefClass that wraps the C++ GeoDaWeight +class. +See C++ functions in rcpp_weights.cpp
+p_LISA class is a RefClass that wraps the C++ LISA class. +See C++ functions in rcpp_lisa.cpp
+Percentile breaks data into 6 groups: the lowest 1 +10-50
+percentile_breaks(df)+ +
df | +A data frame with selected variable. E.g. guerry["Crm_prs"] |
+
---|
A vector of numeric values of computed breaks
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIpercentile_breaks(guerry['Crm_prs']) +#> [1] 5984.50 12153.00 18785.00 29692.00 36380.15
Quantile breaks data into groups that each have the same number +of observations
+quantile_breaks(k, df)+ +
k | +A numeric value indicates how many breaks |
+
---|---|
df | +A data frame with selected variable. E.g. guerry["Crm_prs"] |
+
A vector of numeric values of computed breaks
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIquantile_breaks(k=5, guerry['Crm_prs']) +#> [1] 13270.5 17704.5 21476.5 26743.5
Create a Queen contiguity weights with options of "order", +"include lower order" and "precision threshold"
+queen_weights( + sf_obj, + order = 1, + include_lower_order = FALSE, + precision_threshold = 0 +)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
order | +(Optional) Order of contiguity |
+
include_lower_order | +(Optional) Whether or not the lower order +neighbors should be included in the weights structure |
+
precision_threshold | +(Optional) The precision of the underlying shape +file is insufficient to allow for an exact match of coordinates to determine +which polygons are neighbors |
+
An instance of Weight-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone II#> name value +#> 1 number of observations: 85 +#> 2 is symmetric: TRUE +#> 3 sparsity: 0.0581314878892734 +#> 4 # min neighbors: 2 +#> 5 # max neighbors: 8 +#> 6 # mean neighbors: 4.94117647058824 +#> 7 # median neighbors: 5 +#> 8 has isolates: FALSE
Create a spatial weights object from a .GAL file
+read_gal(file_path, id_vec = c())+ +
file_path | +The file paht of the .GAL file |
+
---|---|
id_vec | +The id_vec is the id values used in the .GAL file. +Default is empty. |
+
A weights object
+ +Create a spatial weights object from a .GWT file
+read_gwt(file_path, id_vec = c())+ +
file_path | +The file paht of the .GWT file |
+
---|---|
id_vec | +The id_vec is the id values used in the .GWT file. +Default is empty. |
+
A weights object
+ +Create a spatial weights object from a .SWM file
+read_swm(file_path, id_vec = numeric())+ +
file_path | +The file paht of the .SWM file |
+
---|---|
id_vec | +The id_vec is the id values used in the .SWM file. +e.g. c(0,1,2,3,...) |
+
A weights object
+ +R/clustering.R
+ redcap.Rd
REDCAP (Regionalization with dynamically constrained agglomerative +clustering and partitioning) is developed by D. Guo (2008). Like SKATER, REDCAP +starts from building a spanning tree with 4 different ways (single-linkage, average-linkage, ward-linkage +and the complete-linkage). The single-linkage way leads to build a minimum spanning tree. +Then,REDCAP provides 2 different ways (first-order and full-order constraining) to +prune the tree to find clusters. The first-order approach with a minimum spanning tree is +exactly the same with SKATER. In GeoDa and pygeoda, the following methods are provided: +\* First-order and Single-linkage +\* Full-order and Complete-linkage +\* Full-order and Average-linkage +\* Full-order and Single-linkage +\* Full-order and Ward-linkage
+redcap( + k, + w, + df, + method = "fullorder-averagelinkage", + bound_variable = data.frame(), + min_bound = 0, + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789, + cpu_threads = 6 +)+ +
k | +The number of clusters |
+
---|---|
w | +An instance of Weight class |
+
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
method | +"firstorder-singlelinkage", "fullorder-completelinkage", "fullorder-averagelinkage","fullorder-singlelinkage", "fullorder-wardlinkage" |
+
bound_variable | +(optional) A data frame with selected bound variabl |
+
min_bound | +(optional) A minimum bound value that applies to all clusters |
+
scale_method | +(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(int,optional) The seed for random number generator. Defaults to 123456789. |
+
cpu_threads | +(optional) The number of cpu threads used for parallel computation |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +guerry_clusters <- redcap(4, queen_w, data, "fullorder-completelinkage") +guerry_clusters +} +
Create a Rook contiguity weights with options of "order", +"include lower order" and "precision threshold"
+rook_weights( + sf_obj, + order = 1, + include_lower_order = FALSE, + precision_threshold = 0 +)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
order | +(Optional) Order of contiguity |
+
include_lower_order | +(Optional) Whether or not the lower order +neighbors should be included in the weights structure |
+
precision_threshold | +(Optional) The precision of the underlying shape +file is insufficient to allow for an exact match of coordinates to determine +which polygons are neighbors |
+
An instance of Weight-class
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone II#> name value +#> 1 number of observations: 85 +#> 2 is symmetric: TRUE +#> 3 sparsity: 0.0581314878892734 +#> 4 # min neighbors: 2 +#> 5 # max neighbors: 8 +#> 6 # mean neighbors: 4.94117647058824 +#> 7 # median neighbors: 5 +#> 8 has isolates: FALSE
Save spatial weights to a file
+save_weights(gda_w, id_variable, out_path, layer_name = "")+ +
gda_w | +A Weight object |
+
---|---|
id_variable | +The id variable (a data.frame) that defines the unique +value of each observation when saving a weights file |
+
out_path | +The path of an output weights file |
+
layer_name | +(optional) The name of the layer of input dataset |
+
A boolean value indicates if save successfully or failed
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +save_weights(quen_w, guerry_df['CODE_DE'], out_path = '/path/Guerry_r.gal') +} +
Spatially constrained hierarchical clustering is a special form of constrained clustering, where the constraint is based on contiguity (common borders). +The method builds up the clusters using agglomerative hierarchical clustering methods: +single linkage, complete linkage, average linkage and Ward's method (a special form of centroid linkage). +Meanwhile, it also maintains the spatial contiguity when merging two clusters.
+schc( + k, + w, + df, + method = "average", + bound_variable = data.frame(), + min_bound = 0, + scale_method = "standardize", + distance_method = "euclidean" +)+ +
k | +The number of clusters |
+
---|---|
w | +An instance of Weight class |
+
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
method | +"single", "complete", "average","ward" |
+
bound_variable | +(optional) A data frame with selected bound variabl |
+
min_bound | +(optional) A minimum bound value that applies to all clusters |
+
scale_method | +One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +guerry_clusters <- schc(4, queen_w, data, "complete") +guerry_clusters +#> $Clusters +#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +#> [39] 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +#> [77] 1 1 1 1 1 1 1 1 1 +#> +#> $`Total sum of squares` +#> [1] 504 +#> +#> $`Within-cluster sum of squares` +#> [1] 78.13831 54.75868 81.49771 63.48675 80.60111 65.74389 +#> +#> $`Total within-cluster sum of squares` +#> [1] 79.77355 +#> +#> $`The ratio of between to total sum of squares` +#> [1] 0.1582809 +#>
Set neighbors for idx-th observation, idx starts from 1
+set_neighbors(gda_w, idx, nbrs)+ +
gda_w | +A Weight object |
+
---|---|
idx | +A value indicates idx-th observation, idx start from 1 |
+
nbrs | +A list indicates the neighbors of idx-th observation +(id start from 1) |
+
+if (FALSE) { +new_w <- create_weights(10) +set_neighbors(new_w, 1, c(2,3)) +update_weights(new_w) +} +
R/weights.R
+ set_neighbors_with_weights.Rd
Set neighbors and the associated weights values for idx-th +observation, idx starts from 1
+set_neighbors_with_weights(gda_w, idx, nbrs, wvals)+ +
gda_w | +A Weight object |
+
---|---|
idx | +A value indicates idx-th observation, idx start from 1 |
+
nbrs | +A list indicates the neighbors of idx-th observation +(id start from 1) |
+
wvals | +A list indicates the associated weights values of the neighbors |
+
+if (FALSE) { +new_w <- create_weights(10) +set_neighbors(new_w, 1, c(2,3)) +update_weights(new_w) +} +
Create an instance of geoda-class from a 'sf' object returned +from 'st_read()' function. NOTE: The table content is NOT used to create an +instance of geoda-class.
+sf_to_geoda(sf_obj, with_table = TRUE)+ +
sf_obj | +An instance of 'sf' object |
+
---|---|
with_table | +A boolean flag indicates if table is copied from sf object +to create geoda object. Default is TRUE. |
+
An instance of geoda-class
+ +SKATER forms clusters by spatially partitioning data that has +similar values for features of interest.
+skater( + k, + w, + df, + bound_variable = data.frame(), + min_bound = 0, + scale_method = "standardize", + distance_method = "euclidean", + random_seed = 123456789, + cpu_threads = 6 +)+ +
k | +The number of clusters |
+
---|---|
w | +An instance of Weight class |
+
df | +A data frame with selected variables only. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
+
bound_variable | +(optional) A data frame with selected bound variable |
+
min_bound | +(optional) A minimum bound value that applies to all clusters |
+
scale_method | +One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
+
distance_method | +(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan" |
+
random_seed | +(int,optional) The seed for random number generator. Defaults to 123456789. |
+
cpu_threads | +(optional) The number of cpu threads used for parallel computation |
+
A list of numeric vectors represents a group of clusters
+A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIqueen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +guerry_clusters <- skater(4, queen_w, data) +guerry_clusters +#> $Clusters +#> [1] 3 2 3 1 1 1 2 1 2 1 1 1 2 1 1 3 3 3 2 4 3 1 2 1 2 2 4 1 1 1 1 1 4 3 4 1 2 1 +#> [39] 4 3 3 4 2 1 1 1 4 4 2 2 4 2 2 4 2 3 2 2 4 2 3 1 1 1 2 2 1 2 3 4 2 2 2 2 3 2 +#> [77] 1 1 1 1 3 3 3 2 2 +#> +#> $`Total sum of squares` +#> [1] 504 +#> +#> $`Within-cluster sum of squares` +#> [1] 57.89077 59.95242 28.72571 69.38030 62.30781 66.65809 +#> +#> $`Total within-cluster sum of squares` +#> [1] 159.0849 +#> +#> $`The ratio of between to total sum of squares` +#> [1] 0.3156447 +#>
Create an instance of geoda-class from a 'sp' object. NOTE: The +table content is NOT used to create an instance of geoda-class.
+sp_to_geoda(sp_obj, with_table = TRUE)+ +
sp_obj | +An instance of 'sp' object |
+
---|---|
with_table | +A boolean flag indicates if table is copied from sf object +to create geoda object. Default is TRUE |
+
An instance of geoda-class
+ +Compute the spatial lag for idx-th observation using selected +variable and current weights matrix
+spatial_lag(gda_w, df)+ +
gda_w | +A Weight object |
+
---|---|
df | +A data frame with selected variable only. E.g. guerry["Crm_prs"] |
+
A data.frame with one column "Spatial Lag"
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +crm_lag <- spatial_lag(queen_w, guerry["Crm_prs"]) +crm_lag +} +
Spatial validation provides a collection of validation measures including +1. fragmentations (entropy, simpson), 2. join count ratio, 3. compactness (isoperimeter quotient) +and 4. diameter.
+spatial_validation(sf_obj, clusters, w)+ +
sf_obj | +An sf (simple feature) object |
+
---|---|
clusters | +A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) |
+
w | +An instance of Weight class |
+
A list with names "Is Spatially Constrained", "Fragmentation", "Join Count Ratio", +"Compactness", and "Diameter".
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] +clusters <- skater(5, queen_w, data) +results <- spatial_validation(guerry, clusters, queen_w) +results +} +
Standard deviation breaks first transforms data to standard +deviation units (mean=0, stddev=1), and then divide the range of values into +6 groups.
+stddev_breaks(df)+ +
df | +A data frame with selected variable. E.g. guerry["Crm_prs"] |
+
---|
A vector of numeric values of computed breaks
+ ++library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +#> Reading layer `Guerry' from data source +#> `/private/var/folders/v5/tcgvkld90l3921n755r7p25h0000gq/T/RtmpCbxwFw/temp_libpath229d5718c5a/rgeoda/extdata/Guerry.shp' +#> using driver `ESRI Shapefile' +#> Simple feature collection with 85 features and 29 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441 +#> Projected CRS: NTF (Paris) / Lambert zone IIstddev_breaks(guerry['Crm_prs']) +#> [1] 5362.458 12661.699 19960.941 27260.183 34559.425
Override the summary() function for spatial weights
+# S3 method for Weight +summary(object, ...)+ +
object | +A Weight object |
+
---|---|
... | +summary optional parameters |
+
A summary description of an instance of Weight-class
+ ++if (FALSE) { +library(sf) +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +summary(queen_w) +} +
Update meta data of a spatial weights. This function can be used +after calling `set_neighbor()` function .
+update_weights(gda_w)+ +
gda_w | +A Weight object |
+
---|
+if (FALSE) { +new_w <- create_weights(10) +set_neighbors(new_w, 1, c(2,3)) +update_weights(new_w) +} +
Get sparsity (
+weights_sparsity(gda_w)+ +
gda_w | +A Weight object |
+
---|
A numeric value of spatial weights sparsity
+ ++if (FALSE) { +guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") +guerry <- st_read(guerry_path) +queen_w <- queen_weights(guerry) +weights_sparsity(queen_w) +} +