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 @@ + + + + + + + + +Page not found (404) • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +Content not found. Please use links in the navbar. + +
+ + + +
+ + + + +
+ + + + + + + + diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 0000000..c39eacc --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,156 @@ + + + + + + + + +Articles • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+

All vignettes

+

+ +
+
Tutorial of rgeoda
+
+
+
+
+
+ + + +
+ + + + + + + + diff --git a/docs/articles/rgeoda_tutorial.html b/docs/articles/rgeoda_tutorial.html new file mode 100644 index 0000000..5920581 --- /dev/null +++ b/docs/articles/rgeoda_tutorial.html @@ -0,0 +1,1122 @@ + + + + + + + +Tutorial of rgeoda • rgeoda + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

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.

+
+

+1. Install 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
+
+
+

+2. Load Spatial Data

+

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.

+
+
+

+3. Spatial Weights

+

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:

+ +
+

+3.1 Queen Contiguity Weights

+

Contiguity 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:

+
+

+Attributes of Weight object

+
+is_symmetric(queen_w)
+
## [1] TRUE
+
+has_isolates(queen_w)
+
## [1] FALSE
+ +
## [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
+
+
+
+

+3.2 Rook Contiguity Weights

+

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
+
+
+

+3.3 Distance Based Weights

+

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:

+ +

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
+
+
+

+3.4 K-Nearest Neighbor Weights

+

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
+
+
+

+3.5 Kernel Weights

+

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

+
    +
  • triangular
  • +
  • uniform
  • +
  • quadratic
  • +
  • epanechnikov
  • +
  • quartic
  • +
  • gaussian
  • +
+

Two functions are provided in rgeoda to create kernel weights.

+
+

+Use kernel_weights for Kernel Weights with adaptive bandwidth

+

To 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
+
+
+

+Use kernel_knn_weights for Kernel Weights with adaptive bandwidth

+

To 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
+
+
+
+
+

+4 Local Indicators of Spatial Association–LISA

+

rgeoda provides following methods for local spatial autocorrelation statistics:

+
    +
  • Local Moran: local_moran(), local_moran_eb()
  • +
  • Local Geary: local_geary(), local_multigeary()
  • +
  • Local Getis-Ord statistics: local_g() and local_gstar()
  • +
  • Local Join Count: local_joincount(), local_bijoincount(), local_multijoincount()
  • +
  • Quantile LISA: local_quantilelisa(), local_multiquantilelisa()
  • +
  • Local Neighbor Match Test: neighbor_match_test()
  • +
+

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.

+
+

+4.1 Local Moran

+

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:

+
    +
  • lisa_clusters(): Get the local cluster indicators returned from LISA computation.
  • +
  • lisa_colors(): Get the cluster colors of LISA computation.
  • +
  • lisa_labels(): Get the cluster labels of LISA computation.
  • +
  • lisa_values(): Get the local spatial autocorrelation values returned from LISA computation.
  • +
  • lisa_num_nbrs(): Get the number of neighbors of every observations in LISA computation.
  • +
  • lisa_pvalues(): Get the local pseudo-p values of significance returned from LISA computation.
  • +
  • lisa_fdr(): Get the False Discovery Rate (FDR) in LISA.
  • +
  • lisa_bo(): Get the False Discovery Rate (FDR) in LISA.
  • +
+

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
+
+
+

+4.2 Local Geary

+

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
+
+
+

+4.3 Multivariate Local Geary:

+

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
+
+
+

+4.4 Local Getis-Ord Statistics

+

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
+
+
+

+4.5 Local Join Count

+

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
+
+

+4.6 Bivariate and Multivariate Local Join Count:

+

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:

+ +
##  [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:

+ +
##  [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:

+ +
##  [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
+
+
+
+

+4.7 Quantile LISA

+

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:

+ +
##  [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
+ +
##  [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:

+ +
##  [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
+ +
##  [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
+
+
+

+4.8 Bivariate Local Moran

+

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')])
+
+
+
+

+5 Spatial Clustering

+

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')]
+
+

+5.1 SKATER

+

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”.

+
+
+

+5.2 REDCAP

+

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:

+
    +
  • First-order and Single-linkage
  • +
  • Full-order and Complete-linkage
  • +
  • Full-order and Average-linkage
  • +
  • Full-order and Single-linkage
  • +
  • Full-order and Wards-linkage
  • +
+

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
+
+
+

+5.3 Spatially Constrained Hierarchical Clucstering

+

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
+
+
+

+5.4 AZP

+

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:

+
    +
  • greedy
  • +
  • Tabu Search
  • +
  • Simulated Annealing
  • +
+
+

+5.4.1 AZP greedy

+

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
+
+
+

+5.4.2 AZP Simulated Annealing

+

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
+
+ +
+
+

+5.5 Max-p

+

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:

+
    +
  • greedy
  • +
  • Tabu Search
  • +
  • Simulated Annealing
  • +
+

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.

+
+
+

+5.5.1 Max-p greedy

+

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")
+
+ +
+

+5.5.3 Max-p Simulated Annealing

+

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.

+
+
+
+

+6 Exploratory Spatial Data 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.

+
+

+6.1 Start from sf package

+

The 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
+

+
+
+

+6.2 ESDA with rgeoda

+

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.

+
+
+

+6.3 Create Local Moran Map

+

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")
+

+
+
+
+ + + +
+ + + + +
+ + + + + + diff --git a/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-62-1.png b/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-62-1.png new file mode 100644 index 0000000..816ab4f Binary files /dev/null and b/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-62-1.png differ diff --git a/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-64-1.png b/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-64-1.png new file mode 100644 index 0000000..83f2ac4 Binary files /dev/null and b/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-64-1.png differ diff --git a/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-67-1.png b/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-67-1.png new file mode 100644 index 0000000..09e6aa8 Binary files /dev/null and b/docs/articles/rgeoda_tutorial_files/figure-html/unnamed-chunk-67-1.png differ diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 0000000..8a9b6ec --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,160 @@ + + + + + + + + +Authors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
    +
  • +

    Xun Li. Author, maintainer. +

    +
  • +
  • +

    Luc Anselin. Author. +

    +
  • +
+ +
+ +
+ + + + +
+ + + + + + + + diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css new file mode 100644 index 0000000..5a85941 --- /dev/null +++ b/docs/bootstrap-toc.css @@ -0,0 +1,60 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ + +/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ + +/* All levels of nav */ +nav[data-toggle='toc'] .nav > li > a { + display: block; + padding: 4px 20px; + font-size: 13px; + font-weight: 500; + color: #767676; +} +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 19px; + color: #563d7c; + text-decoration: none; + background-color: transparent; + border-left: 1px solid #563d7c; +} +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 18px; + font-weight: bold; + color: #563d7c; + background-color: transparent; + border-left: 2px solid #563d7c; +} + +/* Nav: second level (shown on .active) */ +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} +nav[data-toggle='toc'] .nav .nav > li > a { + padding-top: 1px; + padding-bottom: 1px; + padding-left: 30px; + font-size: 12px; + font-weight: normal; +} +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 29px; +} +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 28px; + font-weight: 500; +} + +/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ +nav[data-toggle='toc'] .nav > .active > ul { + display: block; +} diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js new file mode 100644 index 0000000..1cdd573 --- /dev/null +++ b/docs/bootstrap-toc.js @@ -0,0 +1,159 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ +(function() { + 'use strict'; + + window.Toc = { + helpers: { + // return all matching elements in the set, or their descendants + findOrFilter: function($el, selector) { + // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ + // http://stackoverflow.com/a/12731439/358804 + var $descendants = $el.find(selector); + return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); + }, + + generateUniqueIdBase: function(el) { + var text = $(el).text(); + var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); + return anchor || el.tagName.toLowerCase(); + }, + + generateUniqueId: function(el) { + var anchorBase = this.generateUniqueIdBase(el); + for (var i = 0; ; i++) { + var anchor = anchorBase; + if (i > 0) { + // add suffix + anchor += '-' + i; + } + // check if ID already exists + if (!document.getElementById(anchor)) { + return anchor; + } + } + }, + + generateAnchor: function(el) { + if (el.id) { + return el.id; + } else { + var anchor = this.generateUniqueId(el); + el.id = anchor; + return anchor; + } + }, + + createNavList: function() { + return $(''); + }, + + createChildNavList: function($parent) { + var $childList = this.createNavList(); + $parent.append($childList); + return $childList; + }, + + generateNavEl: function(anchor, text) { + var $a = $(''); + $a.attr('href', '#' + anchor); + $a.text(text); + var $li = $('
  • '); + $li.append($a); + return $li; + }, + + generateNavItem: function(headingEl) { + var anchor = this.generateAnchor(headingEl); + var $heading = $(headingEl); + var text = $heading.data('toc-text') || $heading.text(); + return this.generateNavEl(anchor, text); + }, + + // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). + getTopLevel: function($scope) { + for (var i = 1; i <= 6; i++) { + var $headings = this.findOrFilter($scope, 'h' + i); + if ($headings.length > 1) { + return i; + } + } + + return 1; + }, + + // returns the elements for the top level, and the next below it + getHeadings: function($scope, topLevel) { + var topSelector = 'h' + topLevel; + + var secondaryLevel = topLevel + 1; + var secondarySelector = 'h' + secondaryLevel; + + return this.findOrFilter($scope, topSelector + ',' + secondarySelector); + }, + + getNavLevel: function(el) { + return parseInt(el.tagName.charAt(1), 10); + }, + + populateNav: function($topContext, topLevel, $headings) { + var $context = $topContext; + var $prevNav; + + var helpers = this; + $headings.each(function(i, el) { + var $newNav = helpers.generateNavItem(el); + var navLevel = helpers.getNavLevel(el); + + // determine the proper $context + if (navLevel === topLevel) { + // use top level + $context = $topContext; + } else if ($prevNav && $context === $topContext) { + // create a new level of the tree and switch to it + $context = helpers.createChildNavList($prevNav); + } // else use the current $context + + $context.append($newNav); + + $prevNav = $newNav; + }); + }, + + parseOps: function(arg) { + var opts; + if (arg.jquery) { + opts = { + $nav: arg + }; + } else { + opts = arg; + } + opts.$scope = opts.$scope || $(document.body); + return opts; + } + }, + + // accepts a jQuery object, or an options object + init: function(opts) { + opts = this.helpers.parseOps(opts); + + // ensure that the data attribute is in place for styling + opts.$nav.attr('data-toggle', 'toc'); + + var $topContext = this.helpers.createChildNavList(opts.$nav); + var topLevel = this.helpers.getTopLevel(opts.$scope); + var $headings = this.helpers.getHeadings(opts.$scope, topLevel); + this.helpers.populateNav($topContext, topLevel, $headings); + } + }; + + $(function() { + $('nav[data-toggle="toc"]').each(function(i, el) { + var $nav = $(el); + Toc.init($nav); + }); + }); +})(); diff --git a/docs/docsearch.css b/docs/docsearch.css new file mode 100644 index 0000000..e5f1fe1 --- /dev/null +++ b/docs/docsearch.css @@ -0,0 +1,148 @@ +/* Docsearch -------------------------------------------------------------- */ +/* + Source: https://github.com/algolia/docsearch/ + License: MIT +*/ + +.algolia-autocomplete { + display: block; + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1 +} + +.algolia-autocomplete .ds-dropdown-menu { + width: 100%; + min-width: none; + max-width: none; + padding: .75rem 0; + background-color: #fff; + background-clip: padding-box; + border: 1px solid rgba(0, 0, 0, .1); + box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); +} + +@media (min-width:768px) { + .algolia-autocomplete .ds-dropdown-menu { + width: 175% + } +} + +.algolia-autocomplete .ds-dropdown-menu::before { + display: none +} + +.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { + padding: 0; + background-color: rgb(255,255,255); + border: 0; + max-height: 80vh; +} + +.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { + margin-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion { + padding: 0; + overflow: visible +} + +.algolia-autocomplete .algolia-docsearch-suggestion--category-header { + padding: .125rem 1rem; + margin-top: 0; + font-size: 1.3em; + font-weight: 500; + color: #00008B; + border-bottom: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { + float: none; + padding-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { + float: none; + width: auto; + padding: 0; + text-align: left +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content { + float: none; + width: auto; + padding: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content::before { + display: none +} + +.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { + padding-top: .75rem; + margin-top: .75rem; + border-top: 1px solid rgba(0, 0, 0, .1) +} + +.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { + display: block; + padding: .1rem 1rem; + margin-bottom: 0.1; + font-size: 1.0em; + font-weight: 400 + /* display: none */ +} + +.algolia-autocomplete .algolia-docsearch-suggestion--title { + display: block; + padding: .25rem 1rem; + margin-bottom: 0; + font-size: 0.9em; + font-weight: 400 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--text { + padding: 0 1rem .5rem; + margin-top: -.25rem; + font-size: 0.8em; + font-weight: 400; + line-height: 1.25 +} + +.algolia-autocomplete .algolia-docsearch-footer { + width: 110px; + height: 20px; + z-index: 3; + margin-top: 10.66667px; + float: right; + font-size: 0; + line-height: 0; +} + +.algolia-autocomplete .algolia-docsearch-footer--logo { + background-image: url("data:image/svg+xml;utf8,"); + background-repeat: no-repeat; + background-position: 50%; + background-size: 100%; + overflow: hidden; + text-indent: -9000px; + width: 100%; + height: 100%; + display: block; + transform: translate(-8px); +} + +.algolia-autocomplete .algolia-docsearch-suggestion--highlight { + color: #FF8C00; + background: rgba(232, 189, 54, 0.1) +} + + +.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { + box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) +} + +.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { + background-color: rgba(192, 192, 192, .15) +} diff --git a/docs/docsearch.js b/docs/docsearch.js new file mode 100644 index 0000000..b35504c --- /dev/null +++ b/docs/docsearch.js @@ -0,0 +1,85 @@ +$(function() { + + // register a handler to move the focus to the search bar + // upon pressing shift + "/" (i.e. "?") + $(document).on('keydown', function(e) { + if (e.shiftKey && e.keyCode == 191) { + e.preventDefault(); + $("#search-input").focus(); + } + }); + + $(document).ready(function() { + // do keyword highlighting + /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ + var mark = function() { + + var referrer = document.URL ; + var paramKey = "q" ; + + if (referrer.indexOf("?") !== -1) { + var qs = referrer.substr(referrer.indexOf('?') + 1); + var qs_noanchor = qs.split('#')[0]; + var qsa = qs_noanchor.split('&'); + var keyword = ""; + + for (var i = 0; i < qsa.length; i++) { + var currentParam = qsa[i].split('='); + + if (currentParam.length !== 2) { + continue; + } + + if (currentParam[0] == paramKey) { + keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); + } + } + + if (keyword !== "") { + $(".contents").unmark({ + done: function() { + $(".contents").mark(keyword); + } + }); + } + } + }; + + mark(); + }); +}); + +/* Search term highlighting ------------------------------*/ + +function matchedWords(hit) { + var words = []; + + var hierarchy = hit._highlightResult.hierarchy; + // loop to fetch from lvl0, lvl1, etc. + for (var idx in hierarchy) { + words = words.concat(hierarchy[idx].matchedWords); + } + + var content = hit._highlightResult.content; + if (content) { + words = words.concat(content.matchedWords); + } + + // return unique words + var words_uniq = [...new Set(words)]; + return words_uniq; +} + +function updateHitURL(hit) { + + var words = matchedWords(hit); + var url = ""; + + if (hit.anchor) { + url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; + } else { + url = hit.url + '?q=' + escape(words.join(" ")); + } + + return url; +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..0de0915 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,284 @@ + + + + + + + +R Library for Spatial Data Analysis • rgeoda + + + + + + + + + + +
    +
    + + + + +
    +
    +
    + + +

    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

    +
    +

    +Installation

    +
    +install.packages("rgeoda")
    +

    cran statuscran releasecran downloads

    +
    +
    +

    +Quick Start

    +
    +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')])
    + + +
    +
    +

    +Current version 0.0.8

    +
      +
    • Map Classification +
        +
      • NaturalBreaks
      • +
      • QuantileBreaks
      • +
      • Hinge15Breaks
      • +
      • Hinge30Breaks
      • +
      • PercentileBreaks
      • +
      • StddevBreaks
      • +
      +
    • +
    • Spatial Weights +
        +
      • Queen
      • +
      • Rook
      • +
      • Distance based
      • +
      • K-Nearest Neighbor
      • +
      • Kernel
      • +
      • Read GAL/GWT/SWM weights
      • +
      +
    • +
    • Spatial Autocorrelation +
        +
      • Local Moran
      • +
      • Bivariate Local Moran
      • +
      • Local Moran EB Rates
      • +
      • Local Geary
      • +
      • Local Getis-Ord
      • +
      • Multivariate Local Geary
      • +
      • Local Join Count
      • +
      • Bivariate Local Join Count
      • +
      • (Multivariate) Colocation Local Join Count
      • +
      • Quantile LISA
      • +
      • Multivariate Quantile LISA
      • +
      • Neighbor Match Test
      • +
      +
    • +
    • Spatial Clustering +
        +
      • SCHC Spatial Constrained Hierarchical Clustering +
          +
        • Single-linkage
        • +
        • Complete-linkage
        • +
        • Average-linkage
        • +
        • Ward-linkage
        • +
        +
      • +
      • SKATER
      • +
      • REDCAP +
          +
        • 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
        • +
        +
      • +
      • AZP +
          +
        • greedy
        • +
        • Tabu Search
        • +
        • Simulated Annealing
        • +
        +
      • +
      • Max-p +
          +
        • greedy
        • +
        • Tabu Search
        • +
        • Simulated Annealing
        • +
        +
      • +
      +
    • +
    +
    +
    +

    +Build and install from source code

    +

    In R console, one can use devtools to install rgeoda from its source package:

    +
    +devtools::install_github("geodacenter/rgeoda")
    +
    +

    +Mac

    +

    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/.

    +
    +
    +

    +Windows

    +

    On Windows, the Rtools needs to be installed first. https://cran.r-project.org/bin/windows/Rtools/

    +
    +
    +

    +Linux

    +

    For Linux users, the “Build Essential Tools” needs to be installed first.

    +
    sudo apt-get update
    +sudo apt-get install build-essential
    +
    +
    +
    +
    + + +
    + + +
    + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + diff --git a/docs/link.svg b/docs/link.svg new file mode 100644 index 0000000..88ad827 --- /dev/null +++ b/docs/link.svg @@ -0,0 +1,12 @@ + + + + + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 0000000..1273238 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,367 @@ +/* Sticky footer */ + +/** + * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ + * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css + * + * .Site -> body > .container + * .Site-content -> body > .container .row + * .footer -> footer + * + * Key idea seems to be to ensure that .container and __all its parents__ + * have height set to 100% + * + */ + +html, body { + height: 100%; +} + +body { + position: relative; +} + +body > .container { + display: flex; + height: 100%; + flex-direction: column; +} + +body > .container .row { + flex: 1 0 auto; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; + flex-shrink: 0; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Fix bug in bootstrap (only seen in firefox) */ +summary { + display: list-item; +} + +/* Typographic tweaking ---------------------------------*/ + +.contents .page-header { + margin-top: calc(-60px + 1em); +} + +dd { + margin-left: 3em; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -40px; +} + +/* Navbar submenu --------------------------*/ + +.dropdown-submenu { + position: relative; +} + +.dropdown-submenu>.dropdown-menu { + top: 0; + left: 100%; + margin-top: -6px; + margin-left: -1px; + border-radius: 0 6px 6px 6px; +} + +.dropdown-submenu:hover>.dropdown-menu { + display: block; +} + +.dropdown-submenu>a:after { + display: block; + content: " "; + float: right; + width: 0; + height: 0; + border-color: transparent; + border-style: solid; + border-width: 5px 0 5px 5px; + border-left-color: #cccccc; + margin-top: 5px; + margin-right: -10px; +} + +.dropdown-submenu:hover>a:after { + border-left-color: #ffffff; +} + +.dropdown-submenu.pull-left { + float: none; +} + +.dropdown-submenu.pull-left>.dropdown-menu { + left: -100%; + margin-left: 10px; + border-radius: 6px 0 6px 6px; +} + +/* Sidebar --------------------------*/ + +#pkgdown-sidebar { + margin-top: 30px; + position: -webkit-sticky; + position: sticky; + top: 70px; +} + +#pkgdown-sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#pkgdown-sidebar h2:first-child { + margin-top: 0; +} + +#pkgdown-sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* bootstrap-toc tweaks ------------------------------------------------------*/ + +/* All levels of nav */ + +nav[data-toggle='toc'] .nav > li > a { + padding: 4px 20px 4px 6px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; +} + +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 5px; + color: inherit; + border-left: 1px solid #878787; +} + +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 5px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; + border-left: 2px solid #878787; +} + +/* Nav: second level (shown on .active) */ + +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} + +nav[data-toggle='toc'] .nav .nav > li > a { + padding-left: 16px; + font-size: 1.35rem; +} + +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 15px; +} + +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 15px; + font-weight: 500; + font-size: 1.35rem; +} + +/* orcid ------------------------------------------------------------------- */ + +.orcid { + font-size: 16px; + color: #A6CE39; + /* margins are required by official ORCID trademark and display guidelines */ + margin-left:4px; + margin-right:4px; + vertical-align: middle; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} + +.ref-index td {vertical-align: top; min-width: 100px} +.ref-index .icon {width: 40px;} +.ref-index .alias {width: 40%;} +.ref-index-icons .alias {width: calc(40% - 40px);} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre code { + overflow: auto; + word-wrap: normal; + white-space: pre; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #fff; + display: block; + height: auto; +} + +code a, pre a { + color: #375f84; +} + +a.sourceLine:hover { + text-decoration: none; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + +/* Clipboard --------------------------*/ + +.hasCopyButton { + position: relative; +} + +.btn-copy-ex { + position: absolute; + right: 0; + top: 0; + visibility: hidden; +} + +.hasCopyButton:hover button.btn-copy-ex { + visibility: visible; +} + +/* headroom.js ------------------------ */ + +.headroom { + will-change: transform; + transition: transform 200ms linear; +} +.headroom--pinned { + transform: translateY(0%); +} +.headroom--unpinned { + transform: translateY(-100%); +} + +/* mark.js ----------------------------*/ + +mark { + background-color: rgba(255, 255, 51, 0.5); + border-bottom: 2px solid rgba(255, 153, 51, 0.3); + padding: 1px; +} + +/* vertical spacing after htmlwidgets */ +.html-widget { + margin-bottom: 10px; +} + +/* fontawesome ------------------------ */ + +.fab { + font-family: "Font Awesome 5 Brands" !important; +} + +/* don't display links in code chunks when printing */ +/* source: https://stackoverflow.com/a/10781533 */ +@media print { + code a:link:after, code a:visited:after { + content: ""; + } +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 0000000..7e7048f --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,108 @@ +/* http://gregfranko.com/blog/jquery-best-practices/ */ +(function($) { + $(function() { + + $('.navbar-fixed-top').headroom(); + + $('body').css('padding-top', $('.navbar').height() + 10); + $(window).resize(function(){ + $('body').css('padding-top', $('.navbar').height() + 10); + }); + + $('[data-toggle="tooltip"]').tooltip(); + + var cur_path = paths(location.pathname); + var links = $("#navbar ul li a"); + var max_length = -1; + var pos = -1; + for (var i = 0; i < links.length; i++) { + if (links[i].getAttribute("href") === "#") + continue; + // Ignore external links + if (links[i].host !== location.host) + continue; + + var nav_path = paths(links[i].pathname); + + var length = prefix_length(nav_path, cur_path); + if (length > max_length) { + max_length = length; + pos = i; + } + } + + // Add class to parent
  • , and enclosing
  • if in dropdown + if (pos >= 0) { + var menu_anchor = $(links[pos]); + menu_anchor.parent().addClass("active"); + menu_anchor.closest("li.dropdown").addClass("active"); + } + }); + + function paths(pathname) { + var pieces = pathname.split("/"); + pieces.shift(); // always starts with / + + var end = pieces[pieces.length - 1]; + if (end === "index.html" || end === "") + pieces.pop(); + return(pieces); + } + + // Returns -1 if not found + function prefix_length(needle, haystack) { + if (needle.length > haystack.length) + return(-1); + + // Special case for length-0 haystack, since for loop won't run + if (haystack.length === 0) { + return(needle.length === 0 ? 0 : -1); + } + + for (var i = 0; i < haystack.length; i++) { + if (needle[i] != haystack[i]) + return(i); + } + + return(haystack.length); + } + + /* Clipboard --------------------------*/ + + function changeTooltipMessage(element, msg) { + var tooltipOriginalTitle=element.getAttribute('data-original-title'); + element.setAttribute('data-original-title', msg); + $(element).tooltip('show'); + element.setAttribute('data-original-title', tooltipOriginalTitle); + } + + if(ClipboardJS.isSupported()) { + $(document).ready(function() { + var copyButton = ""; + + $(".examples, div.sourceCode").addClass("hasCopyButton"); + + // Insert copy buttons: + $(copyButton).prependTo(".hasCopyButton"); + + // Initialize tooltips: + $('.btn-copy-ex').tooltip({container: 'body'}); + + // Initialize clipboard: + var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { + text: function(trigger) { + return trigger.parentNode.textContent; + } + }); + + clipboardBtnCopies.on('success', function(e) { + changeTooltipMessage(e.trigger, 'Copied!'); + e.clearSelection(); + }); + + clipboardBtnCopies.on('error', function() { + changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); + }); + }); + } +})(window.jQuery || window.$) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml new file mode 100644 index 0000000..d254024 --- /dev/null +++ b/docs/pkgdown.yml @@ -0,0 +1,7 @@ +pandoc: 2.3.1 +pkgdown: 1.6.1 +pkgdown_sha: ~ +articles: + rgeoda_tutorial: rgeoda_tutorial.html +last_built: 2021-09-07T23:07Z + diff --git a/docs/reference/LISA-class.html b/docs/reference/LISA-class.html new file mode 100644 index 0000000..86f7af2 --- /dev/null +++ b/docs/reference/LISA-class.html @@ -0,0 +1,217 @@ + + + + + + + + +LISA class (Internally Used) — LISA-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    A LISA-class that wrappers the statistics of LISA computation

    +
    + + + +

    Fields

    + + + +
    +
    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

    + +
    +

    Methods

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

    + +
    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png new file mode 100644 index 0000000..17a3580 Binary files /dev/null and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/Weight-class.html b/docs/reference/Weight-class.html new file mode 100644 index 0000000..245a91f --- /dev/null +++ b/docs/reference/Weight-class.html @@ -0,0 +1,224 @@ + + + + + + + + +Weight class (Internally Used) — Weight-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    A wrapper class for p_GeoDaWeight class

    +
    + + + +

    Fields

    + + + +
    +
    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

    + +
    +

    Methods

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

    + +
    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/as.data.frame.geoda.html b/docs/reference/as.data.frame.geoda.html new file mode 100644 index 0000000..cc819fa --- /dev/null +++ b/docs/reference/as.data.frame.geoda.html @@ -0,0 +1,188 @@ + + + + + + + + +convert rgeoda instance to data.frame — as.data.frame.geoda • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Override the as.data.frame function for rgeoda instance

    +
    + +
    # S3 method for geoda
    +as.data.frame(x, row.names = NULL, optional = FALSE, ...)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    A data.frame object

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/as.geoda.html b/docs/reference/as.geoda.html new file mode 100644 index 0000000..16d6a39 --- /dev/null +++ b/docs/reference/as.geoda.html @@ -0,0 +1,185 @@ + + + + + + + + +Create an instance of geoda-class from either an 'sf' or 'sp' object — as.geoda • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of geoda-class

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/as.matrix.Weight.html b/docs/reference/as.matrix.Weight.html new file mode 100644 index 0000000..dff8479 --- /dev/null +++ b/docs/reference/as.matrix.Weight.html @@ -0,0 +1,192 @@ + + + + + + + + +spatial weights to matrix — as.matrix.Weight • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Convert a GeoDa spatial weights object to a Matrix object

    +
    + +
    # S3 method for Weight
    +as.matrix(x, rownames = NULL, rownames.value = NULL, ...)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    A matrix object

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/azp_greedy.html b/docs/reference/azp_greedy.html new file mode 100644 index 0000000..5d4370a --- /dev/null +++ b/docs/reference/azp_greedy.html @@ -0,0 +1,232 @@ + + + + + + + + +A greedy algorithm to solve the AZP problem — azp_greedy • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/azp_sa.html b/docs/reference/azp_sa.html new file mode 100644 index 0000000..d704904 --- /dev/null +++ b/docs/reference/azp_sa.html @@ -0,0 +1,242 @@ + + + + + + + + +A simulated annealing algorithm to solve the AZP problem — azp_sa • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/azp_tabu.html b/docs/reference/azp_tabu.html new file mode 100644 index 0000000..18b4ed9 --- /dev/null +++ b/docs/reference/azp_tabu.html @@ -0,0 +1,242 @@ + + + + + + + + +A tabu algorithm to solve the AZP problem — azp_tabu • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/create_weights.html b/docs/reference/create_weights.html new file mode 100644 index 0000000..5e86c6b --- /dev/null +++ b/docs/reference/create_weights.html @@ -0,0 +1,174 @@ + + + + + + + + +Create an empty weights — create_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create an empty weights

    +
    + +
    create_weights(num_obs)
    + +

    Arguments

    + + + + + + +
    num_obs

    The number of observations for this empty weights

    + +

    Value

    + +

    An instance of Weight-class

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/distance_weights.html b/docs/reference/distance_weights.html new file mode 100644 index 0000000..13f86f9 --- /dev/null +++ b/docs/reference/distance_weights.html @@ -0,0 +1,228 @@ + + + + + + + + +Distance-based Spatial Weights — distance_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create a distance-based weights

    +
    + +
    distance_weights(
    +  sf_obj,
    +  dist_thres,
    +  power = 1,
    +  is_inverse = FALSE,
    +  is_arc = FALSE,
    +  is_mile = TRUE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    #> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
    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
    dist_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/eb_rates.html b/docs/reference/eb_rates.html new file mode 100644 index 0000000..5d59b31 --- /dev/null +++ b/docs/reference/eb_rates.html @@ -0,0 +1,185 @@ + + + + + + + + +Empirical Bayes(EB) Rate — eb_rates • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    The function to compute EB Rate from an event variable and a +base variable.

    +
    + +
    eb_rates(df)
    + +

    Arguments

    + + + + + + +
    df

    A data frame with two selected variable: one is "event", anothor is +"base" variable. E.g. guerry[c("hr60", "po60")]

    + +

    Value

    + +

    A data.frame with two columns "EB Rate" and "IsNull".

    + +

    Examples

    +
    if (FALSE) { +library(sf) +nat <- st_read("natregimes.shp") +ebr <- eb_rates(nat[c("HR60", "PO60")]) +ebr +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_distance_weights.html b/docs/reference/gda_distance_weights.html new file mode 100644 index 0000000..60bc3fb --- /dev/null +++ b/docs/reference/gda_distance_weights.html @@ -0,0 +1,214 @@ + + + + + + + + +(For internally use and test only) Distance-based Spatial Weights — gda_distance_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create a distance-based weights

    +
    + +
    gda_distance_weights(
    +  geoda_obj,
    +  dist_thres,
    +  power = 1,
    +  is_inverse = FALSE,
    +  is_arc = FALSE,
    +  is_mile = TRUE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_kernel_knn_weights.html b/docs/reference/gda_kernel_knn_weights.html new file mode 100644 index 0000000..f5dfd05 --- /dev/null +++ b/docs/reference/gda_kernel_knn_weights.html @@ -0,0 +1,234 @@ + + + + + + + + +(For internally use and test only) K-NN Kernel Spatial Weights — gda_kernel_knn_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_kernel_weights.html b/docs/reference/gda_kernel_weights.html new file mode 100644 index 0000000..1077f7e --- /dev/null +++ b/docs/reference/gda_kernel_weights.html @@ -0,0 +1,231 @@ + + + + + + + + +(For internally use and test only) Distance-based Kernel Spatial +Weights — gda_kernel_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_knn_weights.html b/docs/reference/gda_knn_weights.html new file mode 100644 index 0000000..cf0b348 --- /dev/null +++ b/docs/reference/gda_knn_weights.html @@ -0,0 +1,216 @@ + + + + + + + + +(For internally use and test only) K-Nearest Neighbors-based Spatial +Weights — gda_knn_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_min_distthreshold.html b/docs/reference/gda_min_distthreshold.html new file mode 100644 index 0000000..41a8859 --- /dev/null +++ b/docs/reference/gda_min_distthreshold.html @@ -0,0 +1,189 @@ + + + + + + + + +(For internally use and test only) Minimum Distance Threshold for +Distance-based Weights — gda_min_distthreshold • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + +
    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'.

    + +

    Value

    + +

    A numeric value of minimum threshold of distance

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_queen_weights.html b/docs/reference/gda_queen_weights.html new file mode 100644 index 0000000..83f57d1 --- /dev/null +++ b/docs/reference/gda_queen_weights.html @@ -0,0 +1,204 @@ + + + + + + + + +(For internally use and test only) Queen Contiguity Spatial Weights — gda_queen_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/gda_rook_weights.html b/docs/reference/gda_rook_weights.html new file mode 100644 index 0000000..f0bb548 --- /dev/null +++ b/docs/reference/gda_rook_weights.html @@ -0,0 +1,204 @@ + + + + + + + + +(For internally use and test only) Rook Contiguity Spatial Weights — gda_rook_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/geoda-class.html b/docs/reference/geoda-class.html new file mode 100644 index 0000000..d57ca30 --- /dev/null +++ b/docs/reference/geoda-class.html @@ -0,0 +1,208 @@ + + + + + + + + +'geoda' class — geoda-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    'geoda' is a RefClass that wraps the C++ GeoDa class +(via p_GeoDa defines in rgeoda.R)

    +
    + + + +

    Fields

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

    + +
    +

    Methods

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

    + +
    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/geoda_open.html b/docs/reference/geoda_open.html new file mode 100644 index 0000000..dbcfc86 --- /dev/null +++ b/docs/reference/geoda_open.html @@ -0,0 +1,187 @@ + + + + + + + + +Create an instance of geoda-class by reading from an ESRI Shapefile +dataset — geoda_open • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create an instance of geoda-class by reading from an ESRI +Shapefile dataset.

    +
    + +
    geoda_open(ds_path)
    + +

    Arguments

    + + + + + + +
    ds_path

    (character) The path of the spatial dataset

    + +

    Value

    + +

    An instance of geoda-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/get_neighbors.html b/docs/reference/get_neighbors.html new file mode 100644 index 0000000..fac74cc --- /dev/null +++ b/docs/reference/get_neighbors.html @@ -0,0 +1,187 @@ + + + + + + + + +Neighbors of one observation — get_neighbors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get neighbors for idx-th observation, idx starts from 1

    +
    + +
    get_neighbors(gda_w, idx)
    + +

    Arguments

    + + + + + + + + + + +
    gda_w

    A Weight object

    idx

    A value indicates idx-th observation, idx start from 1

    + +

    Value

    + +

    A numeric vector of the neighbor indices, which start from 1

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/get_neighbors_weights.html b/docs/reference/get_neighbors_weights.html new file mode 100644 index 0000000..b7116a7 --- /dev/null +++ b/docs/reference/get_neighbors_weights.html @@ -0,0 +1,189 @@ + + + + + + + + +Weights values of the neighbors of one observation — get_neighbors_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the associated weights values of neighbors for idx-th +observation

    +
    + +
    get_neighbors_weights(gda_w, idx)
    + +

    Arguments

    + + + + + + + + + + +
    gda_w

    A Weight object

    idx

    A value indicates idx-th observation, idx start from 1

    + +

    Value

    + +

    A numeric vector of the neighbor indices, which start from 1

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/has_isolates.html b/docs/reference/has_isolates.html new file mode 100644 index 0000000..ad22dfc --- /dev/null +++ b/docs/reference/has_isolates.html @@ -0,0 +1,184 @@ + + + + + + + + +Isolation/Island in Spatial Weights — has_isolates • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Check if weights matrix has isolates, or if any observation has +no neighbors

    +
    + +
    has_isolates(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    A boolean value indicates if weights matrix is symmetric

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/hinge15_breaks.html b/docs/reference/hinge15_breaks.html new file mode 100644 index 0000000..151d8ac --- /dev/null +++ b/docs/reference/hinge15_breaks.html @@ -0,0 +1,189 @@ + + + + + + + + +(Box) Hinge15 Breaks — hinge15_breaks • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Hinge15 breaks data into 6 groups like box plot groups +(Lower outlier, < 25

    +
    + +
    hinge15_breaks(df)
    + +

    Arguments

    + + + + + + +
    df

    A data frame with selected variable. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A vector of numeric values of computed breaks

    + +

    Examples

    +
    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
    hinge15_breaks(guerry['Crm_prs']) +
    #> [1] -2356.5 14790.0 18785.0 26221.0 43367.5
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/hinge30_breaks.html b/docs/reference/hinge30_breaks.html new file mode 100644 index 0000000..64a5233 --- /dev/null +++ b/docs/reference/hinge30_breaks.html @@ -0,0 +1,189 @@ + + + + + + + + +(Box) Hinge30 Breaks — hinge30_breaks • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Hinge30 breaks data into 6 groups like box plot groups +(Lower outlier, < 25

    +
    + +
    hinge30_breaks(df)
    + +

    Arguments

    + + + + + + +
    df

    A data frame with selected variable. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A vector of numeric values of computed breaks

    + +

    Examples

    +
    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
    hinge30_breaks(guerry['Crm_prs']) +
    #> [1] -19503 14790 18785 26221 60514
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 0000000..ec1184a --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,696 @@ + + + + + + + + +Function reference • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +

    All functions

    +

    +
    +

    LISA-class

    +

    LISA class (Internally Used)

    +

    Weight-class

    +

    Weight class (Internally Used)

    +

    as.data.frame(<geoda>)

    +

    convert rgeoda instance to data.frame

    +

    as.geoda()

    +

    Create an instance of geoda-class from either an 'sf' or 'sp' object

    +

    as.matrix(<Weight>)

    +

    spatial weights to matrix

    +

    azp_greedy()

    +

    A greedy algorithm to solve the AZP problem

    +

    azp_sa()

    +

    A simulated annealing algorithm to solve the AZP problem

    +

    azp_tabu()

    +

    A tabu algorithm to solve the AZP problem

    +

    create_weights()

    +

    Create an empty weights

    +

    distance_weights()

    +

    Distance-based Spatial Weights

    +

    eb_rates()

    +

    Empirical Bayes(EB) Rate

    +

    gda_distance_weights()

    +

    (For internally use and test only) Distance-based Spatial Weights

    +

    gda_kernel_knn_weights()

    +

    (For internally use and test only) K-NN Kernel Spatial Weights

    +

    gda_kernel_weights()

    +

    (For internally use and test only) Distance-based Kernel Spatial +Weights

    +

    gda_knn_weights()

    +

    (For internally use and test only) K-Nearest Neighbors-based Spatial +Weights

    +

    gda_min_distthreshold()

    +

    (For internally use and test only) Minimum Distance Threshold for +Distance-based Weights

    +

    gda_queen_weights()

    +

    (For internally use and test only) Queen Contiguity Spatial Weights

    +

    gda_rook_weights()

    +

    (For internally use and test only) Rook Contiguity Spatial Weights

    +

    geoda-class

    +

    'geoda' class

    +

    geoda_open()

    +

    Create an instance of geoda-class by reading from an ESRI Shapefile +dataset

    +

    get_neighbors()

    +

    Neighbors of one observation

    +

    get_neighbors_weights()

    +

    Weights values of the neighbors of one observation

    +

    has_isolates()

    +

    Isolation/Island in Spatial Weights

    +

    hinge15_breaks()

    +

    (Box) Hinge15 Breaks

    +

    hinge30_breaks()

    +

    (Box) Hinge30 Breaks

    +

    is_symmetric()

    +

    Symmetry of Weights Matrix

    +

    join_count_ratio()

    +

    Join Count Ratio

    +

    kernel_knn_weights()

    +

    K-NN Kernel Spatial Weights

    +

    kernel_weights()

    +

    Distance-based Kernel Spatial Weights

    +

    knn_weights()

    +

    K-Nearest Neighbors-based Spatial Weights

    +

    lisa_bo()

    +

    Bonferroni bound value of local spatial autocorrelation

    +

    lisa_clusters()

    +

    Get local cluster indicators

    +

    lisa_colors()

    +

    Get cluster colors

    +

    lisa_fdr()

    +

    False Discovery Rate value of local spatial autocorrelation

    +

    lisa_labels()

    +

    Get cluster labels

    +

    lisa_num_nbrs()

    +

    Get numbers of neighbors for all observations

    +

    lisa_pvalues()

    +

    Get pseudo-p values of LISA

    +

    lisa_values()

    +

    Get LISA values

    +

    local_bijoincount()

    +

    Bivariate Local Join Count Statistics

    +

    local_bimoran()

    +

    Bivariate Local Moran Statistics

    +

    local_g()

    +

    Local Getis-Ord's G Statistics

    +

    local_geary()

    +

    Local Geary Statistics

    +

    local_gstar()

    +

    Local Getis-Ord's G* Statistics

    +

    local_joincount()

    +

    Local Join Count Statistics

    +

    local_moran()

    +

    Local Moran Statistics

    +

    local_moran_eb()

    +

    Local Moran with Empirical Bayes(EB) Rate

    +

    local_multigeary()

    +

    Local Multivariate Geary Statistics

    +

    local_multijoincount()

    +

    (Multivariate) Colocation Local Join Count Statistics

    +

    local_multiquantilelisa()

    +

    Multivariate Quantile LISA Statistics

    +

    local_quantilelisa()

    +

    Quantile LISA Statistics

    +

    make_spatial()

    +

    Make Spatial

    +

    max_neighbors()

    +

    Maximum Neighbors of Spatial Weights

    +

    maxp_greedy()

    +

    A greedy algorithm to solve the max-p-region problem

    +

    maxp_sa()

    +

    A simulated annealing algorithm to solve the max-p-region problem

    +

    maxp_tabu()

    +

    A tabu-search algorithm to solve the max-p-region problem

    +

    mean_neighbors()

    +

    Mean Neighbors of Spatial Weights

    +

    median_neighbors()

    +

    Median Neighbors of Spatial Weights

    +

    min_distthreshold()

    +

    Minimum Distance Threshold for Distance-based Weights

    +

    min_neighbors()

    +

    Minimum Neighbors of Spatial Weights

    +

    natural_breaks()

    +

    Natural Breaks (Jenks)

    +

    neighbor_match_test()

    +

    Local Neighbor Match Test

    +

    p_GeoDa-class

    +

    p_GeoDa

    +

    p_GeoDaTable-class

    +

    p_GeoDaTable

    +

    p_GeoDaWeight-class

    +

    p_GeoDaWeight

    +

    p_LISA-class

    +

    p_LISA

    +

    percentile_breaks()

    +

    Percentile Breaks

    +

    quantile_breaks()

    +

    Quantile Breaks

    +

    queen_weights()

    +

    Queen Contiguity Spatial Weights

    +

    read_gal()

    +

    Read a .GAL file

    +

    read_gwt()

    +

    Read a .GWT file

    +

    read_swm()

    +

    Read a .SWM file

    +

    redcap()

    +

    Regionalization with dynamically constrained agglomerative clustering and partitioning

    +

    rook_weights()

    +

    Rook Contiguity Spatial Weights

    +

    save_weights()

    +

    Save Spatial Weights

    +

    schc()

    +

    Spatially Constrained Hierarchical Clucstering (SCHC)

    +

    set_neighbors()

    +

    Set neighbors of an observation

    +

    set_neighbors_with_weights()

    +

    Set neighbors and weights values of an observation

    +

    sf_to_geoda()

    +

    Create an instance of geoda-class from a 'sf' object

    +

    skater()

    +

    Spatial C(K)luster Analysis by Tree Edge Removal

    +

    sp_to_geoda()

    +

    Create an instance of geoda-class from a 'sp' object

    +

    spatial_lag()

    +

    Spatial Lag

    +

    spatial_validation()

    +

    Spatial Validation

    +

    stddev_breaks()

    +

    Standard Deviation Breaks

    +

    summary(<Weight>)

    +

    Summary of Spatial Weights

    +

    update_weights()

    +

    Update meta data of a spatial weights

    +

    weights_sparsity()

    +

    Sparsity of Spatial Weights

    +
    + + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/is_symmetric.html b/docs/reference/is_symmetric.html new file mode 100644 index 0000000..1633a74 --- /dev/null +++ b/docs/reference/is_symmetric.html @@ -0,0 +1,182 @@ + + + + + + + + +Symmetry of Weights Matrix — is_symmetric • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Check if weights matrix is symmetric

    +
    + +
    is_symmetric(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    A boolean value indicates if weights matrix is symmetric

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/join_count_ratio.html b/docs/reference/join_count_ratio.html new file mode 100644 index 0000000..3f699b3 --- /dev/null +++ b/docs/reference/join_count_ratio.html @@ -0,0 +1,194 @@ + + + + + + + + +Join Count Ratio — join_count_ratio • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + +
    clusters

    A cluster classification variable (categorical values from a dataframe or values returned from cluster functions)

    w

    An instance of Weight class

    + +

    Value

    + +

    A data.frame with names "Cluster", "N", "Neighbors", "Join Count", "Ratio"

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/kernel_knn_weights.html b/docs/reference/kernel_knn_weights.html new file mode 100644 index 0000000..eab200b --- /dev/null +++ b/docs/reference/kernel_knn_weights.html @@ -0,0 +1,248 @@ + + + + + + + + +K-NN Kernel Spatial Weights — kernel_knn_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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
    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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/kernel_weights.html b/docs/reference/kernel_weights.html new file mode 100644 index 0000000..eb9d3df --- /dev/null +++ b/docs/reference/kernel_weights.html @@ -0,0 +1,242 @@ + + + + + + + + +Distance-based Kernel Spatial Weights — kernel_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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
    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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/knn_weights.html b/docs/reference/knn_weights.html new file mode 100644 index 0000000..ad51901 --- /dev/null +++ b/docs/reference/knn_weights.html @@ -0,0 +1,227 @@ + + + + + + + + +K-Nearest Neighbors-based Spatial Weights — knn_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create a k-nearest neighbors based spatial weights

    +
    + +
    knn_weights(
    +  sf_obj,
    +  k,
    +  power = 1,
    +  is_inverse = FALSE,
    +  is_arc = FALSE,
    +  is_mile = TRUE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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
    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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_bo.html b/docs/reference/lisa_bo.html new file mode 100644 index 0000000..64f57f5 --- /dev/null +++ b/docs/reference/lisa_bo.html @@ -0,0 +1,191 @@ + + + + + + + + +Bonferroni bound value of local spatial autocorrelation — lisa_bo • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get Bonferroni bound value based on current LISA computation +and current significat p-value

    +
    + +
    lisa_bo(gda_lisa, current_p)
    + +

    Arguments

    + + + + + + + + + + +
    gda_lisa

    An instance of LISA object

    current_p

    A value of current siginificant p-value

    + +

    Value

    + +

    A numeric value of Bonferroni bound

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_clusters.html b/docs/reference/lisa_clusters.html new file mode 100644 index 0000000..04c3412 --- /dev/null +++ b/docs/reference/lisa_clusters.html @@ -0,0 +1,190 @@ + + + + + + + + +Get local cluster indicators — lisa_clusters • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the local cluster indicators returned from LISA computation.

    +
    + +
    lisa_clusters(gda_lisa, cutoff = 0)
    + +

    Arguments

    + + + + + + + + + + +
    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

    + +

    Value

    + +

    A numeric vector of LISA cluster indicator

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_colors.html b/docs/reference/lisa_colors.html new file mode 100644 index 0000000..97c3e0b --- /dev/null +++ b/docs/reference/lisa_colors.html @@ -0,0 +1,185 @@ + + + + + + + + +Get cluster colors — lisa_colors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the cluster colors of LISA computation.

    +
    + +
    lisa_colors(gda_lisa)
    + +

    Arguments

    + + + + + + +
    gda_lisa

    An instance of LISA object

    + +

    Value

    + +

    A string vector of cluster colors

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_fdr.html b/docs/reference/lisa_fdr.html new file mode 100644 index 0000000..2ddaf7f --- /dev/null +++ b/docs/reference/lisa_fdr.html @@ -0,0 +1,191 @@ + + + + + + + + +False Discovery Rate value of local spatial autocorrelation — lisa_fdr • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get False Discovery Rate value based on current LISA +computation and current significant p-value

    +
    + +
    lisa_fdr(gda_lisa, current_p)
    + +

    Arguments

    + + + + + + + + + + +
    gda_lisa

    An instance of LISA object

    current_p

    A value of current siginificant p-value

    + +

    Value

    + +

    A numeric vector of False Discovery Rate

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_labels.html b/docs/reference/lisa_labels.html new file mode 100644 index 0000000..f2384c4 --- /dev/null +++ b/docs/reference/lisa_labels.html @@ -0,0 +1,185 @@ + + + + + + + + +Get cluster labels — lisa_labels • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get cluster labels of LISA computation.

    +
    + +
    lisa_labels(gda_lisa)
    + +

    Arguments

    + + + + + + +
    gda_lisa

    An instance of LISA object

    + +

    Value

    + +

    A string vector of cluster labels

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_num_nbrs.html b/docs/reference/lisa_num_nbrs.html new file mode 100644 index 0000000..54fec72 --- /dev/null +++ b/docs/reference/lisa_num_nbrs.html @@ -0,0 +1,185 @@ + + + + + + + + +Get numbers of neighbors for all observations — lisa_num_nbrs • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get numbers of neighbors for all observations

    +
    + +
    lisa_num_nbrs(gda_lisa)
    + +

    Arguments

    + + + + + + +
    gda_lisa

    An instance of LISA object

    + +

    Value

    + +

    A numeric vector of the number of neighbors

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_pvalues.html b/docs/reference/lisa_pvalues.html new file mode 100644 index 0000000..5b05765 --- /dev/null +++ b/docs/reference/lisa_pvalues.html @@ -0,0 +1,187 @@ + + + + + + + + +Get pseudo-p values of LISA — lisa_pvalues • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the local pseudo-p values of significance returned from +LISA computation.

    +
    + +
    lisa_pvalues(gda_lisa)
    + +

    Arguments

    + + + + + + +
    gda_lisa

    An instance of LISA object

    + +

    Value

    + +

    A numeric vector of pseudo-p values of local spatial autocorrelation

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/lisa_values.html b/docs/reference/lisa_values.html new file mode 100644 index 0000000..efa6fdb --- /dev/null +++ b/docs/reference/lisa_values.html @@ -0,0 +1,187 @@ + + + + + + + + +Get LISA values — lisa_values • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the local spatial autocorrelation values returned from +LISA computation

    +
    + +
    lisa_values(gda_lisa)
    + +

    Arguments

    + + + + + + +
    gda_lisa

    An instance of LISA object

    + +

    Value

    + +

    A numeric vector of local spatial autocorrelation

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_bijoincount.html b/docs/reference/local_bijoincount.html new file mode 100644 index 0000000..5c33018 --- /dev/null +++ b/docs/reference/local_bijoincount.html @@ -0,0 +1,230 @@ + + + + + + + + +Bivariate Local Join Count Statistics — local_bijoincount • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_bimoran.html b/docs/reference/local_bimoran.html new file mode 100644 index 0000000..3035312 --- /dev/null +++ b/docs/reference/local_bimoran.html @@ -0,0 +1,242 @@ + + + + + + + + +Bivariate Local Moran Statistics — local_bimoran • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_g.html b/docs/reference/local_g.html new file mode 100644 index 0000000..4333fb0 --- /dev/null +++ b/docs/reference/local_g.html @@ -0,0 +1,240 @@ + + + + + + + + +Local Getis-Ord's G Statistics — local_g • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_geary.html b/docs/reference/local_geary.html new file mode 100644 index 0000000..0b59c6a --- /dev/null +++ b/docs/reference/local_geary.html @@ -0,0 +1,240 @@ + + + + + + + + +Local Geary Statistics — local_geary • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_gstar.html b/docs/reference/local_gstar.html new file mode 100644 index 0000000..a13dd66 --- /dev/null +++ b/docs/reference/local_gstar.html @@ -0,0 +1,240 @@ + + + + + + + + +Local Getis-Ord's G* Statistics — local_gstar • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_joincount.html b/docs/reference/local_joincount.html new file mode 100644 index 0000000..9e99801 --- /dev/null +++ b/docs/reference/local_joincount.html @@ -0,0 +1,228 @@ + + + + + + + + +Local Join Count Statistics — local_joincount • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_moran.html b/docs/reference/local_moran.html new file mode 100644 index 0000000..5bdf8be --- /dev/null +++ b/docs/reference/local_moran.html @@ -0,0 +1,242 @@ + + + + + + + + +Local Moran Statistics — local_moran • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_moran_eb.html b/docs/reference/local_moran_eb.html new file mode 100644 index 0000000..45b0b27 --- /dev/null +++ b/docs/reference/local_moran_eb.html @@ -0,0 +1,225 @@ + + + + + + + + +Local Moran with Empirical Bayes(EB) Rate — local_moran_eb • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_multigeary.html b/docs/reference/local_multigeary.html new file mode 100644 index 0000000..98b4a7e --- /dev/null +++ b/docs/reference/local_multigeary.html @@ -0,0 +1,230 @@ + + + + + + + + +Local Multivariate Geary Statistics — local_multigeary • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_multijoincount.html b/docs/reference/local_multijoincount.html new file mode 100644 index 0000000..fedd945 --- /dev/null +++ b/docs/reference/local_multijoincount.html @@ -0,0 +1,232 @@ + + + + + + + + +(Multivariate) Colocation Local Join Count Statistics — local_multijoincount • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_multiquantilelisa.html b/docs/reference/local_multiquantilelisa.html new file mode 100644 index 0000000..64b97be --- /dev/null +++ b/docs/reference/local_multiquantilelisa.html @@ -0,0 +1,242 @@ + + + + + + + + +Multivariate Quantile LISA Statistics — local_multiquantilelisa • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/local_quantilelisa.html b/docs/reference/local_quantilelisa.html new file mode 100644 index 0000000..ba53111 --- /dev/null +++ b/docs/reference/local_quantilelisa.html @@ -0,0 +1,239 @@ + + + + + + + + +Quantile LISA Statistics — local_quantilelisa • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of LISA-class

    + +

    Examples

    +
    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
    queen_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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/make_spatial.html b/docs/reference/make_spatial.html new file mode 100644 index 0000000..bb492b6 --- /dev/null +++ b/docs/reference/make_spatial.html @@ -0,0 +1,192 @@ + + + + + + + + +Make Spatial — make_spatial • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Make spatially constrained clusters from spatially non-constrained clusters +using the contiguity information from the input weights

    +
    + +
    make_spatial(clusters, w)
    + +

    Arguments

    + + + + + + + + + + +
    clusters

    A cluster classification variable (categorical values from a dataframe or values returned from cluster functions)

    w

    An instance of Weight class

    + +

    Value

    + +

    A vector of categorical values (cluster classification)

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/max_neighbors.html b/docs/reference/max_neighbors.html new file mode 100644 index 0000000..52539ac --- /dev/null +++ b/docs/reference/max_neighbors.html @@ -0,0 +1,183 @@ + + + + + + + + +Maximum Neighbors of Spatial Weights — max_neighbors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the number of maximum neighbors of spatial weights

    +
    + +
    max_neighbors(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    The number of maximum neighbors of spatial weights

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/maxp_greedy.html b/docs/reference/maxp_greedy.html new file mode 100644 index 0000000..5cfdcd8 --- /dev/null +++ b/docs/reference/maxp_greedy.html @@ -0,0 +1,240 @@ + + + + + + + + +A greedy algorithm to solve the max-p-region problem — maxp_greedy • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/maxp_sa.html b/docs/reference/maxp_sa.html new file mode 100644 index 0000000..f74d3be --- /dev/null +++ b/docs/reference/maxp_sa.html @@ -0,0 +1,250 @@ + + + + + + + + +A simulated annealing algorithm to solve the max-p-region problem — maxp_sa • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/maxp_tabu.html b/docs/reference/maxp_tabu.html new file mode 100644 index 0000000..a5459d1 --- /dev/null +++ b/docs/reference/maxp_tabu.html @@ -0,0 +1,250 @@ + + + + + + + + +A tabu-search algorithm to solve the max-p-region problem — maxp_tabu • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/mean_neighbors.html b/docs/reference/mean_neighbors.html new file mode 100644 index 0000000..2b20cab --- /dev/null +++ b/docs/reference/mean_neighbors.html @@ -0,0 +1,183 @@ + + + + + + + + +Mean Neighbors of Spatial Weights — mean_neighbors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the number of mean neighbors of spatial weights

    +
    + +
    mean_neighbors(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    The number of mean neighbors of spatial weights

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/median_neighbors.html b/docs/reference/median_neighbors.html new file mode 100644 index 0000000..5ee143e --- /dev/null +++ b/docs/reference/median_neighbors.html @@ -0,0 +1,183 @@ + + + + + + + + +Median Neighbors of Spatial Weights — median_neighbors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the number of median neighbors of spatial weights

    +
    + +
    median_neighbors(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    The number of median neighbors of spatial weights

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/min_distthreshold.html b/docs/reference/min_distthreshold.html new file mode 100644 index 0000000..7b5f2af --- /dev/null +++ b/docs/reference/min_distthreshold.html @@ -0,0 +1,195 @@ + + + + + + + + +Minimum Distance Threshold for Distance-based Weights — min_distthreshold • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + +
    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'.

    + +

    Value

    + +

    A numeric value of minimum threshold of distance

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/min_neighbors.html b/docs/reference/min_neighbors.html new file mode 100644 index 0000000..2e219c0 --- /dev/null +++ b/docs/reference/min_neighbors.html @@ -0,0 +1,183 @@ + + + + + + + + +Minimum Neighbors of Spatial Weights — min_neighbors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get the number of minimum neighbors of spatial weights

    +
    + +
    min_neighbors(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    The number of minimum neighbors of spatial weights

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/natural_breaks.html b/docs/reference/natural_breaks.html new file mode 100644 index 0000000..baa2459 --- /dev/null +++ b/docs/reference/natural_breaks.html @@ -0,0 +1,193 @@ + + + + + + + + +Natural Breaks (Jenks) — natural_breaks • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Natural Breaks group data whose boundaries are set where there +are relatively big differences.

    +
    + +
    natural_breaks(k, df)
    + +

    Arguments

    + + + + + + + + + + +
    k

    A numeric value indicates how many breaks

    df

    A data frame with selected variable. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A vector of numeric values of computed breaks

    + +

    Examples

    +
    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
    natural_breaks(k=5, guerry['Crm_prs']) +
    #> [1] 9474 16722 23316 29872
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/neighbor_match_test.html b/docs/reference/neighbor_match_test.html new file mode 100644 index 0000000..0d358d6 --- /dev/null +++ b/docs/reference/neighbor_match_test.html @@ -0,0 +1,323 @@ + + + + + + + + +Local Neighbor Match Test — neighbor_match_test • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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.

    + +

    Value

    + +

    A data.frame with two columns "Cardinality" and "Probability".

    + +

    Examples

    +
    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
    data <- 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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/p_GeoDa-class.html b/docs/reference/p_GeoDa-class.html new file mode 100644 index 0000000..d3271ad --- /dev/null +++ b/docs/reference/p_GeoDa-class.html @@ -0,0 +1,164 @@ + + + + + + + + +p_GeoDa — p_GeoDa-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    p_GeoDa class is a RefClass that wraps the C++ 'GeoDa' class. +See C++ functions in rcpp_rgeoda.cpp

    +
    + + + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/p_GeoDaTable-class.html b/docs/reference/p_GeoDaTable-class.html new file mode 100644 index 0000000..0b47735 --- /dev/null +++ b/docs/reference/p_GeoDaTable-class.html @@ -0,0 +1,166 @@ + + + + + + + + +p_GeoDaTable — p_GeoDaTable-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    p_GeoDaTable class is a RefClass that wraps the C++ 'GeoDaTable' +class. +See C++ functions in rcpp_rgeoda.cpp

    +
    + + + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/p_GeoDaWeight-class.html b/docs/reference/p_GeoDaWeight-class.html new file mode 100644 index 0000000..9556beb --- /dev/null +++ b/docs/reference/p_GeoDaWeight-class.html @@ -0,0 +1,166 @@ + + + + + + + + +p_GeoDaWeight — p_GeoDaWeight-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    p_GeoDaWeight class is a RefClass that wraps the C++ GeoDaWeight +class. +See C++ functions in rcpp_weights.cpp

    +
    + + + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/p_LISA-class.html b/docs/reference/p_LISA-class.html new file mode 100644 index 0000000..dd04500 --- /dev/null +++ b/docs/reference/p_LISA-class.html @@ -0,0 +1,164 @@ + + + + + + + + +p_LISA — p_LISA-class • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    p_LISA class is a RefClass that wraps the C++ LISA class. +See C++ functions in rcpp_lisa.cpp

    +
    + + + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/percentile_breaks.html b/docs/reference/percentile_breaks.html new file mode 100644 index 0000000..1749b0a --- /dev/null +++ b/docs/reference/percentile_breaks.html @@ -0,0 +1,189 @@ + + + + + + + + +Percentile Breaks — percentile_breaks • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Percentile breaks data into 6 groups: the lowest 1 +10-50

    +
    + +
    percentile_breaks(df)
    + +

    Arguments

    + + + + + + +
    df

    A data frame with selected variable. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A vector of numeric values of computed breaks

    + +

    Examples

    +
    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
    percentile_breaks(guerry['Crm_prs']) +
    #> [1] 5984.50 12153.00 18785.00 29692.00 36380.15
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/quantile_breaks.html b/docs/reference/quantile_breaks.html new file mode 100644 index 0000000..552e447 --- /dev/null +++ b/docs/reference/quantile_breaks.html @@ -0,0 +1,193 @@ + + + + + + + + +Quantile Breaks — quantile_breaks • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Quantile breaks data into groups that each have the same number +of observations

    +
    + +
    quantile_breaks(k, df)
    + +

    Arguments

    + + + + + + + + + + +
    k

    A numeric value indicates how many breaks

    df

    A data frame with selected variable. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A vector of numeric values of computed breaks

    + +

    Examples

    +
    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
    quantile_breaks(k=5, guerry['Crm_prs']) +
    #> [1] 13270.5 17704.5 21476.5 26743.5
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/queen_weights.html b/docs/reference/queen_weights.html new file mode 100644 index 0000000..aba51ea --- /dev/null +++ b/docs/reference/queen_weights.html @@ -0,0 +1,218 @@ + + + + + + + + +Queen Contiguity Spatial Weights — queen_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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
    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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/read_gal.html b/docs/reference/read_gal.html new file mode 100644 index 0000000..4cf3848 --- /dev/null +++ b/docs/reference/read_gal.html @@ -0,0 +1,179 @@ + + + + + + + + +Read a .GAL file — read_gal • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create a spatial weights object from a .GAL file

    +
    + +
    read_gal(file_path, id_vec = c())
    + +

    Arguments

    + + + + + + + + + + +
    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.

    + +

    Value

    + +

    A weights object

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/read_gwt.html b/docs/reference/read_gwt.html new file mode 100644 index 0000000..9e48e29 --- /dev/null +++ b/docs/reference/read_gwt.html @@ -0,0 +1,179 @@ + + + + + + + + +Read a .GWT file — read_gwt • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create a spatial weights object from a .GWT file

    +
    + +
    read_gwt(file_path, id_vec = c())
    + +

    Arguments

    + + + + + + + + + + +
    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.

    + +

    Value

    + +

    A weights object

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/read_swm.html b/docs/reference/read_swm.html new file mode 100644 index 0000000..7d19166 --- /dev/null +++ b/docs/reference/read_swm.html @@ -0,0 +1,179 @@ + + + + + + + + +Read a .SWM file — read_swm • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Create a spatial weights object from a .SWM file

    +
    + +
    read_swm(file_path, id_vec = numeric())
    + +

    Arguments

    + + + + + + + + + + +
    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,...)

    + +

    Value

    + +

    A weights object

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/redcap.html b/docs/reference/redcap.html new file mode 100644 index 0000000..83a138b --- /dev/null +++ b/docs/reference/redcap.html @@ -0,0 +1,254 @@ + + + + + + + + +Regionalization with dynamically constrained agglomerative clustering and partitioning — redcap • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/rook_weights.html b/docs/reference/rook_weights.html new file mode 100644 index 0000000..a14b51a --- /dev/null +++ b/docs/reference/rook_weights.html @@ -0,0 +1,218 @@ + + + + + + + + +Rook Contiguity Spatial Weights — rook_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of Weight-class

    + +

    Examples

    +
    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
    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
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/save_weights.html b/docs/reference/save_weights.html new file mode 100644 index 0000000..f4c1668 --- /dev/null +++ b/docs/reference/save_weights.html @@ -0,0 +1,196 @@ + + + + + + + + +Save Spatial Weights — save_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Save spatial weights to a file

    +
    + +
    save_weights(gda_w, id_variable, out_path, layer_name = "")
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    A boolean value indicates if save successfully or failed

    + +

    Examples

    +
    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') +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/schc.html b/docs/reference/schc.html new file mode 100644 index 0000000..eb6e879 --- /dev/null +++ b/docs/reference/schc.html @@ -0,0 +1,249 @@ + + + + + + + + +Spatially Constrained Hierarchical Clucstering (SCHC) — schc • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    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"
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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"

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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
    queen_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 +#>
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/set_neighbors.html b/docs/reference/set_neighbors.html new file mode 100644 index 0000000..e0b26e9 --- /dev/null +++ b/docs/reference/set_neighbors.html @@ -0,0 +1,187 @@ + + + + + + + + +Set neighbors of an observation — set_neighbors • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Set neighbors for idx-th observation, idx starts from 1

    +
    + +
    set_neighbors(gda_w, idx, nbrs)
    + +

    Arguments

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

    + + +

    Examples

    +
    if (FALSE) { +new_w <- create_weights(10) +set_neighbors(new_w, 1, c(2,3)) +update_weights(new_w) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/set_neighbors_with_weights.html b/docs/reference/set_neighbors_with_weights.html new file mode 100644 index 0000000..bebf227 --- /dev/null +++ b/docs/reference/set_neighbors_with_weights.html @@ -0,0 +1,193 @@ + + + + + + + + +Set neighbors and weights values of an observation — set_neighbors_with_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Set neighbors and the associated weights values for idx-th +observation, idx starts from 1

    +
    + +
    set_neighbors_with_weights(gda_w, idx, nbrs, wvals)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + +
    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

    + + +

    Examples

    +
    if (FALSE) { +new_w <- create_weights(10) +set_neighbors(new_w, 1, c(2,3)) +update_weights(new_w) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/sf_to_geoda.html b/docs/reference/sf_to_geoda.html new file mode 100644 index 0000000..4524a07 --- /dev/null +++ b/docs/reference/sf_to_geoda.html @@ -0,0 +1,183 @@ + + + + + + + + +Create an instance of geoda-class from a 'sf' object — sf_to_geoda • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + +
    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.

    + +

    Value

    + +

    An instance of geoda-class

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/skater.html b/docs/reference/skater.html new file mode 100644 index 0000000..112b0ba --- /dev/null +++ b/docs/reference/skater.html @@ -0,0 +1,251 @@ + + + + + + + + +Spatial C(K)luster Analysis by Tree Edge Removal — skater • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    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".

    + +

    Examples

    +
    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
    queen_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 +#>
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/sp_to_geoda.html b/docs/reference/sp_to_geoda.html new file mode 100644 index 0000000..99156ab --- /dev/null +++ b/docs/reference/sp_to_geoda.html @@ -0,0 +1,181 @@ + + + + + + + + +Create an instance of geoda-class from a 'sp' object — sp_to_geoda • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + +
    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

    + +

    Value

    + +

    An instance of geoda-class

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/spatial_lag.html b/docs/reference/spatial_lag.html new file mode 100644 index 0000000..246f93d --- /dev/null +++ b/docs/reference/spatial_lag.html @@ -0,0 +1,190 @@ + + + + + + + + +Spatial Lag — spatial_lag • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Compute the spatial lag for idx-th observation using selected +variable and current weights matrix

    +
    + +
    spatial_lag(gda_w, df)
    + +

    Arguments

    + + + + + + + + + + +
    gda_w

    A Weight object

    df

    A data frame with selected variable only. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A data.frame with one column "Spatial Lag"

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/spatial_validation.html b/docs/reference/spatial_validation.html new file mode 100644 index 0000000..67c86cc --- /dev/null +++ b/docs/reference/spatial_validation.html @@ -0,0 +1,199 @@ + + + + + + + + +Spatial Validation — spatial_validation • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + + + + + + + + + +
    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

    + +

    Value

    + +

    A list with names "Is Spatially Constrained", "Fragmentation", "Join Count Ratio", +"Compactness", and "Diameter".

    + +

    Examples

    +
    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 +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/stddev_breaks.html b/docs/reference/stddev_breaks.html new file mode 100644 index 0000000..88ccb1a --- /dev/null +++ b/docs/reference/stddev_breaks.html @@ -0,0 +1,191 @@ + + + + + + + + +Standard Deviation Breaks — stddev_breaks • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

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

    Arguments

    + + + + + + +
    df

    A data frame with selected variable. E.g. guerry["Crm_prs"]

    + +

    Value

    + +

    A vector of numeric values of computed breaks

    + +

    Examples

    +
    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
    stddev_breaks(guerry['Crm_prs']) +
    #> [1] 5362.458 12661.699 19960.941 27260.183 34559.425
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/summary.Weight.html b/docs/reference/summary.Weight.html new file mode 100644 index 0000000..0678d2a --- /dev/null +++ b/docs/reference/summary.Weight.html @@ -0,0 +1,188 @@ + + + + + + + + +Summary of Spatial Weights — summary.Weight • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Override the summary() function for spatial weights

    +
    + +
    # S3 method for Weight
    +summary(object, ...)
    + +

    Arguments

    + + + + + + + + + + +
    object

    A Weight object

    ...

    summary optional parameters

    + +

    Value

    + +

    A summary description of an instance of Weight-class

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/update_weights.html b/docs/reference/update_weights.html new file mode 100644 index 0000000..4582f26 --- /dev/null +++ b/docs/reference/update_weights.html @@ -0,0 +1,180 @@ + + + + + + + + +Update meta data of a spatial weights — update_weights • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Update meta data of a spatial weights. This function can be used +after calling `set_neighbor()` function .

    +
    + +
    update_weights(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + + +

    Examples

    +
    if (FALSE) { +new_w <- create_weights(10) +set_neighbors(new_w, 1, c(2,3)) +update_weights(new_w) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/weights_sparsity.html b/docs/reference/weights_sparsity.html new file mode 100644 index 0000000..56a4a54 --- /dev/null +++ b/docs/reference/weights_sparsity.html @@ -0,0 +1,182 @@ + + + + + + + + +Sparsity of Spatial Weights — weights_sparsity • rgeoda + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Get sparsity (

    +
    + +
    weights_sparsity(gda_w)
    + +

    Arguments

    + + + + + + +
    gda_w

    A Weight object

    + +

    Value

    + +

    A numeric value of spatial weights sparsity

    + +

    Examples

    +
    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) +} +
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/man/LISA-class.Rd b/man/LISA-class.Rd index e21ec3c..ff1fbb6 100644 --- a/man/LISA-class.Rd +++ b/man/LISA-class.Rd @@ -38,18 +38,16 @@ computation} \item{\code{GetFDR(current_p)}}{Get the False Discovery Rate value} -\item{\code{GetLabels()}}{Get the cluster labels of LISA computation.} - \item{\code{GetLISAValues()}}{Get the local spatial autocorrelation values returned from LISA computation.} +\item{\code{GetLabels()}}{Get the cluster labels of LISA computation.} + \item{\code{GetLocalSignificanceValues()}}{Get the local pseudo-p values of significance returned from LISA computation.} \item{\code{GetNumNeighbors()}}{Get the number of neighbors of every observations in LISA computation.} -\item{\code{initialize(lisa_obj)}}{Constructor with a LISA object (internally used)} - \item{\code{Run()}}{Call to run LISA computation} \item{\code{SetPermutations(num_perm)}}{Set the number of permutations for the LISA computation} @@ -57,5 +55,7 @@ computation.} \item{\code{SetSignificanceCutoff(cutoff)}}{Set the cutoff value of significance values} \item{\code{SetThreads(num_threads)}}{Set the number of CPU threads for the LISA computation} + +\item{\code{initialize(lisa_obj)}}{Constructor with a LISA object (internally used)} }} diff --git a/man/Weight-class.Rd b/man/Weight-class.Rd index 7c7388a..789e166 100644 --- a/man/Weight-class.Rd +++ b/man/Weight-class.Rd @@ -33,11 +33,11 @@ A wrapper class for p_GeoDaWeight class \section{Methods}{ \describe{ -\item{\code{GetNeighbors(idx)}}{Get neighbors for idx-th observation, idx starts from 0} - \item{\code{GetNeighborWeights(idx)}}{Get weights values of neighbors for idx-th observation, idx starts from 0} +\item{\code{GetNeighbors(idx)}}{Get neighbors for idx-th observation, idx starts from 0} + \item{\code{GetPointer()}}{Get the C++ object pointer (internally used)} \item{\code{GetSparsity()}}{Get sparsity computed from weights matrix} @@ -45,8 +45,6 @@ idx starts from 0} \item{\code{HasIsolates()}}{Check if weights matrix has isolates, or if any observation has no neighbors} -\item{\code{initialize(o_gda_w)}}{Constructor with a GeoDaWeight object (internally used)} - \item{\code{IsSymmetric()}}{Check if weights matrix is symmetric} \item{\code{SaveToFile(out_path, layer_name, id_name, id_values)}}{Save current spatial weights to a file.\cr \cr @@ -64,5 +62,7 @@ id_values : The tuple of values of selected id_name (column/field)} \item{\code{SpatialLag(values)}}{Compute spatial lag values for values of selected variable} \item{\code{Update(updateStats = TRUE)}}{Update the weights meta data} + +\item{\code{initialize(o_gda_w)}}{Constructor with a GeoDaWeight object (internally used)} }} diff --git a/man/join_count_ratio.Rd b/man/join_count_ratio.Rd new file mode 100644 index 0000000..87fe0eb --- /dev/null +++ b/man/join_count_ratio.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/clustering.R +\name{join_count_ratio} +\alias{join_count_ratio} +\title{Join Count Ratio} +\usage{ +join_count_ratio(clusters, w) +} +\arguments{ +\item{clusters}{A cluster classification variable (categorical values from a dataframe or values returned from cluster functions)} + +\item{w}{An instance of Weight class} +} +\value{ +A data.frame with names "Cluster", "N", "Neighbors", "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. +} +\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 +} +} diff --git a/man/local_bimoran.Rd b/man/local_bimoran.Rd new file mode 100644 index 0000000..5bae010 --- /dev/null +++ b/man/local_bimoran.Rd @@ -0,0 +1,50 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/lisa.R +\name{local_bimoran} +\alias{local_bimoran} +\title{Bivariate Local Moran Statistics} +\usage{ +local_bimoran( + w, + df, + permutations = 999, + permutation_method = "complete", + significance_cutoff = 0.05, + cpu_threads = 6, + seed = 123456789 +) +} +\arguments{ +\item{w}{An instance of Weight object} + +\item{df}{A data frame with two selected variable. E.g. guerry[c('Crm_prs','Litercy')]} + +\item{permutations}{(optional) The number of permutations for the LISA +computation} + +\item{permutation_method}{(optional) The permutation method used for the +LISA computation. Options are {'complete', 'lookup'}. Default is 'complete'.} + +\item{significance_cutoff}{(optional) A cutoff value for significance +p-values to filter not-significant clusters} + +\item{cpu_threads}{(optional) The number of cpu threads used for parallel +LISA computation} + +\item{seed}{(optional) The seed for random number generator} +} +\value{ +An instance of LISA-class +} +\description{ +The function to apply bivariate local Moran statistics +} +\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 +} diff --git a/man/make_spatial.Rd b/man/make_spatial.Rd new file mode 100644 index 0000000..2aa2c6e --- /dev/null +++ b/man/make_spatial.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/clustering.R +\name{make_spatial} +\alias{make_spatial} +\title{Make Spatial} +\usage{ +make_spatial(clusters, w) +} +\arguments{ +\item{clusters}{A cluster classification variable (categorical values from a dataframe or values returned from cluster functions)} + +\item{w}{An instance of Weight class} +} +\value{ +A vector of categorical values (cluster classification) +} +\description{ +Make spatially constrained clusters from spatially non-constrained clusters +using the contiguity information from the input weights +} +\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 +} +} diff --git a/man/spatial_validation.Rd b/man/spatial_validation.Rd new file mode 100644 index 0000000..55ca3e4 --- /dev/null +++ b/man/spatial_validation.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/clustering.R +\name{spatial_validation} +\alias{spatial_validation} +\title{Spatial Validation} +\usage{ +spatial_validation(sf_obj, clusters, w) +} +\arguments{ +\item{sf_obj}{An sf (simple feature) object} + +\item{clusters}{A cluster classification variable (categorical values from a dataframe or values returned from cluster functions)} + +\item{w}{An instance of Weight class} +} +\value{ +A list with names "Is Spatially Constrained", "Fragmentation", "Join Count Ratio", +"Compactness", and "Diameter". +} +\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. +} +\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 +} +} diff --git a/src/Makevars b/src/Makevars index cb55a42..d5b9212 100644 --- a/src/Makevars +++ b/src/Makevars @@ -40,6 +40,7 @@ CPP_SRC_FILES = \ $(RGEODALIB)/sa/UniGstar.cpp \ $(RGEODALIB)/sa/UniJoinCount.cpp \ $(RGEODALIB)/sa/UniLocalMoran.cpp \ + $(RGEODALIB)/sa/BiLocalMoran.cpp \ $(RGEODALIB)/clustering/fastcluster.cpp \ $(RGEODALIB)/clustering/redcap.cpp \ $(RGEODALIB)/clustering/redcap_wrapper.cpp \ @@ -48,6 +49,9 @@ CPP_SRC_FILES = \ $(RGEODALIB)/clustering/azp_wrapper.cpp \ $(RGEODALIB)/clustering/schc_wrapper.cpp \ $(RGEODALIB)/clustering/cluster.cpp \ + $(RGEODALIB)/clustering/joincount_ratio.cpp \ + $(RGEODALIB)/clustering/make_spatial.cpp \ + $(RGEODALIB)/clustering/spatial_validation.cpp \ $(RGEODALIB)/knn/ANN.cpp \ $(RGEODALIB)/knn/perf.cpp \ $(RGEODALIB)/knn/kd_util.cpp \ @@ -104,6 +108,7 @@ OBJECTS = \ $(RGEODALIB)/sa/UniGstar.o \ $(RGEODALIB)/sa/UniJoinCount.o \ $(RGEODALIB)/sa/UniLocalMoran.o \ + $(RGEODALIB)/sa/BiLocalMoran.o \ $(RGEODALIB)/clustering/fastcluster.o \ $(RGEODALIB)/clustering/redcap.o \ $(RGEODALIB)/clustering/redcap_wrapper.o \ @@ -112,6 +117,9 @@ OBJECTS = \ $(RGEODALIB)/clustering/azp_wrapper.o \ $(RGEODALIB)/clustering/schc_wrapper.o \ $(RGEODALIB)/clustering/cluster.o \ + $(RGEODALIB)/clustering/joincount_ratio.o \ + $(RGEODALIB)/clustering/make_spatial.o \ + $(RGEODALIB)/clustering/spatial_validation.o \ $(RGEODALIB)/knn/ANN.o \ $(RGEODALIB)/knn/perf.o \ $(RGEODALIB)/knn/kd_util.o \ diff --git a/src/Makevars.win b/src/Makevars.win index 9183435..6643db4 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -44,6 +44,7 @@ CPP_SRC_FILES = \ $(RGEODALIB)/sa/UniGstar.cpp \ $(RGEODALIB)/sa/UniJoinCount.cpp \ $(RGEODALIB)/sa/UniLocalMoran.cpp \ + $(RGEODALIB)/sa/BiLocalMoran.cpp \ $(RGEODALIB)/clustering/redcap.cpp \ $(RGEODALIB)/clustering/redcap_wrapper.cpp \ $(RGEODALIB)/clustering/azp.cpp \ @@ -51,6 +52,9 @@ CPP_SRC_FILES = \ $(RGEODALIB)/clustering/azp_wrapper.cpp \ $(RGEODALIB)/clustering/schc_wrapper.cpp \ $(RGEODALIB)/clustering/cluster.cpp \ + $(RGEODALIB)/clustering/joincount_ratio.cpp \ + $(RGEODALIB)/clustering/make_spatial.cpp \ + $(RGEODALIB)/clustering/spatial_validation.cpp \ $(RGEODALIB)/knn/ANN.cpp \ $(RGEODALIB)/knn/perf.cpp \ $(RGEODALIB)/knn/kd_util.cpp \ @@ -107,6 +111,7 @@ OBJECTS = \ $(RGEODALIB)/sa/UniGstar.o \ $(RGEODALIB)/sa/UniJoinCount.o \ $(RGEODALIB)/sa/UniLocalMoran.o \ + $(RGEODALIB)/sa/BiLocalMoran.o \ $(RGEODALIB)/clustering/redcap.o \ $(RGEODALIB)/clustering/redcap_wrapper.o \ $(RGEODALIB)/clustering/azp.o \ @@ -114,6 +119,9 @@ OBJECTS = \ $(RGEODALIB)/clustering/azp_wrapper.o \ $(RGEODALIB)/clustering/schc_wrapper.o \ $(RGEODALIB)/clustering/cluster.o \ + $(RGEODALIB)/clustering/joincount_ratio.o \ + $(RGEODALIB)/clustering/make_spatial.o \ + $(RGEODALIB)/clustering/spatial_validation.o \ $(RGEODALIB)/knn/ANN.o \ $(RGEODALIB)/knn/perf.o \ $(RGEODALIB)/knn/kd_util.o \ diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index cf97032..e31deb6 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -5,6 +5,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // p_skater Rcpp::List p_skater(int k, SEXP xp_w, Rcpp::List& data, int n_vars, std::string scale_method, std::string distance_method, NumericVector& bound_vals, double min_bound, int seed, int cpu_threads); RcppExport SEXP _rgeoda_p_skater(SEXP kSEXP, SEXP xp_wSEXP, SEXP dataSEXP, SEXP n_varsSEXP, SEXP scale_methodSEXP, SEXP distance_methodSEXP, SEXP bound_valsSEXP, SEXP min_boundSEXP, SEXP seedSEXP, SEXP cpu_threadsSEXP) { @@ -199,6 +204,43 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// p_spatialvalidation +Rcpp::List p_spatialvalidation(SEXP xp_geoda, NumericVector& clusters, SEXP xp_w); +RcppExport SEXP _rgeoda_p_spatialvalidation(SEXP xp_geodaSEXP, SEXP clustersSEXP, SEXP xp_wSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type xp_geoda(xp_geodaSEXP); + Rcpp::traits::input_parameter< NumericVector& >::type clusters(clustersSEXP); + Rcpp::traits::input_parameter< SEXP >::type xp_w(xp_wSEXP); + rcpp_result_gen = Rcpp::wrap(p_spatialvalidation(xp_geoda, clusters, xp_w)); + return rcpp_result_gen; +END_RCPP +} +// p_joincount_ratio +Rcpp::List p_joincount_ratio(NumericVector& clusters, SEXP xp_w); +RcppExport SEXP _rgeoda_p_joincount_ratio(SEXP clustersSEXP, SEXP xp_wSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< NumericVector& >::type clusters(clustersSEXP); + Rcpp::traits::input_parameter< SEXP >::type xp_w(xp_wSEXP); + rcpp_result_gen = Rcpp::wrap(p_joincount_ratio(clusters, xp_w)); + return rcpp_result_gen; +END_RCPP +} +// p_make_spatial +Rcpp::NumericVector p_make_spatial(NumericVector& clusters, SEXP xp_w); +RcppExport SEXP _rgeoda_p_make_spatial(SEXP clustersSEXP, SEXP xp_wSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< NumericVector& >::type clusters(clustersSEXP); + Rcpp::traits::input_parameter< SEXP >::type xp_w(xp_wSEXP); + rcpp_result_gen = Rcpp::wrap(p_make_spatial(clusters, xp_w)); + return rcpp_result_gen; +END_RCPP +} // p_LISA__Run void p_LISA__Run(SEXP xp); RcppExport SEXP _rgeoda_p_LISA__Run(SEXP xpSEXP) { @@ -349,6 +391,24 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// p_bi_localmoran +SEXP p_bi_localmoran(SEXP xp_w, NumericVector& data1, NumericVector& data2, int permutations, std::string permutation_method, double significance_cutoff, int cpu_threads, int seed); +RcppExport SEXP _rgeoda_p_bi_localmoran(SEXP xp_wSEXP, SEXP data1SEXP, SEXP data2SEXP, SEXP permutationsSEXP, SEXP permutation_methodSEXP, SEXP significance_cutoffSEXP, SEXP cpu_threadsSEXP, SEXP seedSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type xp_w(xp_wSEXP); + Rcpp::traits::input_parameter< NumericVector& >::type data1(data1SEXP); + Rcpp::traits::input_parameter< NumericVector& >::type data2(data2SEXP); + Rcpp::traits::input_parameter< int >::type permutations(permutationsSEXP); + Rcpp::traits::input_parameter< std::string >::type permutation_method(permutation_methodSEXP); + Rcpp::traits::input_parameter< double >::type significance_cutoff(significance_cutoffSEXP); + Rcpp::traits::input_parameter< int >::type cpu_threads(cpu_threadsSEXP); + Rcpp::traits::input_parameter< int >::type seed(seedSEXP); + rcpp_result_gen = Rcpp::wrap(p_bi_localmoran(xp_w, data1, data2, permutations, permutation_method, significance_cutoff, cpu_threads, seed)); + return rcpp_result_gen; +END_RCPP +} // p_eb_rate DataFrame p_eb_rate(NumericVector& event_data, NumericVector& base_data); RcppExport SEXP _rgeoda_p_eb_rate(SEXP event_dataSEXP, SEXP base_dataSEXP) { @@ -1184,6 +1244,9 @@ static const R_CallMethodDef CallEntries[] = { {"_rgeoda_p_azp_greedy", (DL_FUNC) &_rgeoda_p_azp_greedy, 11}, {"_rgeoda_p_azp_sa", (DL_FUNC) &_rgeoda_p_azp_sa, 13}, {"_rgeoda_p_azp_tabu", (DL_FUNC) &_rgeoda_p_azp_tabu, 13}, + {"_rgeoda_p_spatialvalidation", (DL_FUNC) &_rgeoda_p_spatialvalidation, 3}, + {"_rgeoda_p_joincount_ratio", (DL_FUNC) &_rgeoda_p_joincount_ratio, 2}, + {"_rgeoda_p_make_spatial", (DL_FUNC) &_rgeoda_p_make_spatial, 2}, {"_rgeoda_p_LISA__Run", (DL_FUNC) &_rgeoda_p_LISA__Run, 1}, {"_rgeoda_p_LISA__SetNumPermutations", (DL_FUNC) &_rgeoda_p_LISA__SetNumPermutations, 2}, {"_rgeoda_p_LISA__SetNumThreads", (DL_FUNC) &_rgeoda_p_LISA__SetNumThreads, 2}, @@ -1197,6 +1260,7 @@ static const R_CallMethodDef CallEntries[] = { {"_rgeoda_p_LISA__GetBO", (DL_FUNC) &_rgeoda_p_LISA__GetBO, 2}, {"_rgeoda_p_LISA__GetFDR", (DL_FUNC) &_rgeoda_p_LISA__GetFDR, 2}, {"_rgeoda_p_localmoran", (DL_FUNC) &_rgeoda_p_localmoran, 7}, + {"_rgeoda_p_bi_localmoran", (DL_FUNC) &_rgeoda_p_bi_localmoran, 8}, {"_rgeoda_p_eb_rate", (DL_FUNC) &_rgeoda_p_eb_rate, 2}, {"_rgeoda_p_localmoran_eb", (DL_FUNC) &_rgeoda_p_localmoran_eb, 8}, {"_rgeoda_p_localgeary", (DL_FUNC) &_rgeoda_p_localgeary, 7}, diff --git a/src/libgeoda b/src/libgeoda index 9d3f202..9d8499c 160000 --- a/src/libgeoda +++ b/src/libgeoda @@ -1 +1 @@ -Subproject commit 9d3f202bc2eb179463c75376dfe10d0a2828f69d +Subproject commit 9d8499c57ede938d2f129b9ea0811a2d94924b2d diff --git a/src/rcpp_clustering.cpp b/src/rcpp_clustering.cpp index 925dfcf..17c7e3f 100644 --- a/src/rcpp_clustering.cpp +++ b/src/rcpp_clustering.cpp @@ -11,6 +11,8 @@ using namespace Rcpp; #include "libgeoda/gda_clustering.h" #include "libgeoda/GenUtils.h" +#include "libgeoda/gda_interface.h" +#include "libgeoda/libgeoda.h" Rcpp::List _create_clustering_result(int num_obs, const std::vector >& cluster_ids, const std::vector >& raw_data) @@ -269,3 +271,210 @@ Rcpp::List p_azp_tabu(int p, SEXP xp_w, Rcpp::List& data, int n_vars, int tabu_l return _create_clustering_result(w->GetNumObs(), cluster_ids, raw_data); } + +// [[Rcpp::export]] +Rcpp::List p_spatialvalidation(SEXP xp_geoda, NumericVector& clusters, SEXP xp_w) +{ + // grab the object as a XPtr (smart pointer) to GeoDa + Rcpp::XPtr ptr(xp_geoda); + GeoDa* geoda = static_cast (R_ExternalPtrAddr(ptr)); + + Rcpp::XPtr ptr_w(xp_w); + GeoDaWeight* w = static_cast (R_ExternalPtrAddr(ptr_w)); + + int n = clusters.size(); + std::vector raw_clusters(n); + + for (int i=0; i< n; ++i) { + raw_clusters[i] = clusters[i]; + } + + ValidationResult result = gda_spatialvalidation(geoda, raw_clusters, w); + + Rcpp::NumericVector jc_v1, jc_v2, jc_v3, jc_v4, jc_v5; + int n_clusters = result.joincount_ratio.size(); + for (int i = 0; i < n_clusters; ++i) { + jc_v1.push_back(i + 1); + jc_v2.push_back(result.joincount_ratio[i].n); + jc_v3.push_back(result.joincount_ratio[i].totalNeighbors); + jc_v4.push_back(result.joincount_ratio[i].totalJoinCount); + jc_v5.push_back(result.joincount_ratio[i].ratio); + } + Rcpp::DataFrame out_joincount = Rcpp::DataFrame::create( + Rcpp::Named("Cluster") = jc_v1, + Rcpp::Named("N") = jc_v2, + Rcpp::Named("Neighbors") = jc_v3, + Rcpp::Named("Join Count") = jc_v4, + Rcpp::Named("Ratio") = jc_v5 + ); + + JoinCountRatio all_jcr = gda_all_joincount_ratio(result.joincount_ratio); + Rcpp::List out_all_joincount = Rcpp::List::create( + Rcpp::Named("N") = all_jcr.n, + Rcpp::Named("Neighbors") = all_jcr.totalNeighbors, + Rcpp::Named("Join Count") = all_jcr.totalJoinCount, + Rcpp::Named("Ratio") = all_jcr.ratio + ); + + Rcpp::List out_fragmentation = Rcpp::List::create( + Rcpp::Named("#Clusters") = result.fragmentation.n, + Rcpp::Named("Entropy") = result.fragmentation.entropy, + Rcpp::Named("Entropy*") = result.fragmentation.std_entropy, + Rcpp::Named("Simpson") = result.fragmentation.simpson, + Rcpp::Named("Simpson*") = result.fragmentation.std_simpson + ); + + if (result.spatially_constrained) { + Rcpp::NumericVector compact_v1, compact_v2, compact_v3, compact_v4; + n_clusters = result.cluster_compactness.size(); + for (int i = 0; i < n_clusters; ++i) { + compact_v1.push_back(i + 1); + compact_v2.push_back(result.cluster_compactness[i].area); + compact_v3.push_back(result.cluster_compactness[i].perimeter); + compact_v4.push_back(result.cluster_compactness[i].isoperimeter_quotient); + } + Rcpp::DataFrame out_compact = Rcpp::DataFrame::create( + Rcpp::Named("Cluster") = compact_v1, + Rcpp::Named("Area") = compact_v2, + Rcpp::Named("Perimeter") = compact_v3, + Rcpp::Named("IPC") = compact_v4 + ); + + Rcpp::NumericVector diameter_v1, diameter_v2, diameter_v3; + n_clusters = result.cluster_diameter.size(); + for (int i = 0; i < n_clusters; ++i) { + diameter_v1.push_back(i + 1); + diameter_v2.push_back(result.cluster_diameter[i].steps); + diameter_v3.push_back(result.cluster_diameter[i].ratio); + } + Rcpp::DataFrame out_diameter = Rcpp::DataFrame::create( + Rcpp::Named("Cluster") = diameter_v1, + Rcpp::Named("Steps") = diameter_v2, + Rcpp::Named("Ratio") = diameter_v3 + ); + Rcpp::List out = Rcpp::List::create( + Rcpp::Named("IsSpatiallyConstrained") = result.spatially_constrained, + Rcpp::Named("Fragmentation") = out_fragmentation, + Rcpp::Named("SubclusterFragmentation") = "N/A: clusters are spatially constrained.", + Rcpp::Named("JoinCountRatio") = out_joincount, + Rcpp::Named("AllJoinCountRatio") = out_all_joincount, + Rcpp::Named("Compactness") = out_compact, + Rcpp::Named("Diameter") = out_diameter + ); + + return out; + + } else { + Rcpp::NumericVector subfrag_v1, subfrag_v2, subfrag_v3, subfrag_v4, subfrag_v5; + Rcpp::NumericVector subfrag_v6, subfrag_v7, subfrag_v8, subfrag_v9, subfrag_v10, subfrag_v11; + n_clusters = result.cluster_fragmentation.size(); + for (int i = 0; i < n_clusters; ++i) { + subfrag_v1.push_back(i + 1); + subfrag_v2.push_back(result.joincount_ratio[i].n); + subfrag_v3.push_back(result.cluster_fragmentation[i].fraction); + subfrag_v4.push_back(result.cluster_fragmentation[i].n); + subfrag_v5.push_back(result.cluster_fragmentation[i].entropy); + subfrag_v6.push_back(result.cluster_fragmentation[i].std_entropy); + subfrag_v7.push_back(result.cluster_fragmentation[i].simpson); + subfrag_v8.push_back(result.cluster_fragmentation[i].std_simpson); + subfrag_v9.push_back(result.cluster_fragmentation[i].min_cluster_size); + subfrag_v10.push_back(result.cluster_fragmentation[i].max_cluster_size); + subfrag_v11.push_back(result.cluster_fragmentation[i].mean_cluster_size); + } + Rcpp::DataFrame out_subfrag = Rcpp::DataFrame::create( + Rcpp::Named("Cluster") = subfrag_v1, + Rcpp::Named("N") = subfrag_v2, + Rcpp::Named("Fraction") = subfrag_v3, + Rcpp::Named("#Sub") = subfrag_v4, + Rcpp::Named("Entropy") = subfrag_v5, + Rcpp::Named("Entropy*") = subfrag_v6, + Rcpp::Named("Simpson") = subfrag_v7, + Rcpp::Named("Simpson*") = subfrag_v8, + Rcpp::Named("Min") = subfrag_v9, + Rcpp::Named("Max") = subfrag_v10, + Rcpp::Named("Mean") = subfrag_v11 + ); + + Rcpp::List out = Rcpp::List::create( + Rcpp::Named("IsSpatiallyConstrained") = result.spatially_constrained, + Rcpp::Named("Fragmentation") = out_fragmentation, + Rcpp::Named("SubclusterFragmentation") = out_subfrag, + Rcpp::Named("JoinCountRatio") = out_joincount, + Rcpp::Named("AllJoinCountRatio") = out_all_joincount, + Rcpp::Named("Compactness") = "N/A: clusters are not spatially constrained.", + Rcpp::Named("Diameter") = "N/A: clusters are not spatially constrained." + ); + + return out; + } + +} + +// [[Rcpp::export]] +Rcpp::List p_joincount_ratio(NumericVector& clusters, SEXP xp_w) +{ + // grab the object as a XPtr (smart pointer) + Rcpp::XPtr ptr_w(xp_w); + GeoDaWeight* w = static_cast (R_ExternalPtrAddr(ptr_w)); + + int n = clusters.size(); + std::vector raw_clusters(n); + + for (int i=0; i< n; ++i) { + raw_clusters[i] = clusters[i]; + } + + std::vector items = gda_joincount_ratio(raw_clusters, w); + JoinCountRatio all_jcr = gda_all_joincount_ratio(items); + + Rcpp::NumericVector jc_v1, jc_v2, jc_v3, jc_v4, jc_v5; + int n_clusters = items.size(); + for (int i = 0; i < n_clusters; ++i) { + jc_v1.push_back(i + 1); + jc_v2.push_back(items[i].n); + jc_v3.push_back(items[i].totalNeighbors); + jc_v4.push_back(items[i].totalJoinCount); + jc_v5.push_back(items[i].ratio); + } + Rcpp::DataFrame out_joincount = Rcpp::DataFrame::create( + Rcpp::Named("Cluster") = jc_v1, + Rcpp::Named("N") = jc_v2, + Rcpp::Named("Neighbors") = jc_v3, + Rcpp::Named("Join Count") = jc_v4, + Rcpp::Named("Ratio") = jc_v5 + ); + + Rcpp::List out_all_joincount = Rcpp::List::create( + Rcpp::Named("N") = all_jcr.n, + Rcpp::Named("Neighbors") = all_jcr.totalNeighbors, + Rcpp::Named("Join Count") = all_jcr.totalJoinCount, + Rcpp::Named("Ratio") = all_jcr.ratio + ); + + Rcpp::List out = Rcpp::List::create( + Rcpp::Named("JoinCountRatio") = out_joincount, + Rcpp::Named("AllJoinCountRatio") = out_all_joincount + ); + + return out; +} + +// [[Rcpp::export]] +Rcpp::NumericVector p_make_spatial(NumericVector& clusters, SEXP xp_w) +{ + // grab the object as a XPtr (smart pointer) + Rcpp::XPtr ptr_w(xp_w); + GeoDaWeight* w = static_cast (R_ExternalPtrAddr(ptr_w)); + + int n = clusters.size(); + std::vector raw_clusters(n); + + for (int i=0; i< n; ++i) { + raw_clusters[i] = clusters[i]; + } + + std::vector result = gda_makespatial(raw_clusters, w); + + Rcpp::NumericVector out(result.begin(), result.end()); + return out; +} \ No newline at end of file diff --git a/src/rcpp_lisa.cpp b/src/rcpp_lisa.cpp index cea3167..c9f521b 100644 --- a/src/rcpp_lisa.cpp +++ b/src/rcpp_lisa.cpp @@ -147,6 +147,29 @@ SEXP p_localmoran(SEXP xp_w, NumericVector data, int permutations, std::string p return lisa_ptr; } +// [[Rcpp::export]] +SEXP p_bi_localmoran(SEXP xp_w, NumericVector& data1, NumericVector& data2, int permutations, std::string permutation_method, double significance_cutoff, int cpu_threads, int seed) +{ + // grab the object as a XPtr (smart pointer) to GeoDaWeight + Rcpp::XPtr ptr(xp_w); + GeoDaWeight* w = static_cast (R_ExternalPtrAddr(ptr)); + + std::vector raw_data1 = as >(data1); + std::vector raw_data2 = as >(data2); + + int n = (int)data1.size(); + std::vector undefs(n, false); + + for (int i=0; i< n; ++i) { + undefs[i] = data1.is_na(i) || data2.is_na(i); + } + + LISA* lisa = gda_bi_localmoran(w, raw_data1, raw_data2, undefs, significance_cutoff, cpu_threads, permutations, permutation_method, seed); + + Rcpp::XPtr lisa_ptr(lisa, true); + return lisa_ptr; +} + // [[Rcpp::export]] DataFrame p_eb_rate(NumericVector& event_data, NumericVector& base_data) { diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..fd66128 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(rgeoda) + +test_check("rgeoda") diff --git a/tests/testthat/test-clustering.R b/tests/testthat/test-clustering.R index 8ba2c32..c0da917 100644 --- a/tests/testthat/test-clustering.R +++ b/tests/testthat/test-clustering.R @@ -1,5 +1,38 @@ context("clustering.R") +testthat::test_that("spatial_validataion", { + 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(6, queen_w, data) + + validation <- spatial_validation(guerry, clusters[[1]], queen_w) + + testthat::expect_equal(validation$IsSpatiallyConstrained, TRUE) + testthat::expect_equal(validation$Fragmentation$Entropy, 1.5302035777210896) + testthat::expect_equal(validation$Fragmentation$`Entropy*`, 0.85402287751287753) + testthat::expect_equal(validation$Fragmentation$Simpson, 0.25619377162629758) + testthat::expect_equal(validation$Fragmentation$`Simpson*`, 1.5371626297577856) + testthat::expect_equal(validation$JoinCountRatio$Ratio, c(0.8571429,0.8923077,0.5846154,0.5454545,0.3846154,0.6666667), tolerance=1e-6) + testthat::expect_equal(validation$Compactness$IPC, c(0.009772352, 0.009914427, 0.029675045, 0.034800225, 0.046733291, 0.035828472)) + testthat::expect_equal(validation$Diameter$Ratio, c(0.2413793, 0.2500000, 0.36363636363, 0.3750000, 0.6000000, 0.5000000)) +}) + +testthat::test_that("make_spatial", { + library(sf) + guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") + guerry <- st_read(guerry_path) + queen_w <- queen_weights(guerry) + + km_clusters <- c(5,2,5,1,3,6,2,5,3,1,5,3,4,5,4,4,4,4,2,6,5,1,3,1,3,3,4,1,1,1,2,1,6,4,1,1,2,4,1,5,5,1,3,1,1,1,2,2,3,2,2,2,2,4,3,4,2,2,2,3,5,1,5,1,3,3,3,2,2,2,3,3,3,3,4,2,1,1,1,1,6,6,4,2,3) + clusters <- make_spatial(km_clusters, queen_w) + + testthat::expect_equal(clusters, c(1, 2, 5, 1, 1, 1,2,1,3,1,5,1,3,5,4,4,4,4,2,6,5,1,2,1,3,3,4,1,1,1,1,1,6,4,4,1,2,1,4,5,5,4,3,1,1,1,4,4,3,2,4,2,2,4,2,4,2,2,4,2,5,1,1,1,2,2,1,2,2,4,3,3,3,3,4,2,1,1,1,1,4,4,4,2,3)) +}) + testthat::test_that("skater", { library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") diff --git a/tests/testthat/test-sa.R b/tests/testthat/test-sa.R index 323f4be..7c31632 100644 --- a/tests/testthat/test-sa.R +++ b/tests/testthat/test-sa.R @@ -15,6 +15,23 @@ testthat::test_that("local_moran", { "Isolated")) }) +testthat::test_that("local_bimoran", { + guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") + guerry <- st_read(guerry_path) + queen_w <- queen_weights(guerry) + + lm <- local_bimoran(queen_w, guerry[c("Crm_prs", "Litercy")]) + lvals <- lisa_values(lm) + pvals <- lisa_pvalues(lm) + lbls <- lisa_labels(lm) + + testthat::expect_equal(lvals[[1]], 0.392663447638106) + testthat::expect_equal(pvals[[1]], 0.2690) + testthat::expect_equal(lbls, c("Not significant", "High-High", "Low-Low", + "Low-High", "High-Low", "Undefined", + "Isolated")) +}) + testthat::test_that("local_multiquantilelisa", { guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) diff --git a/tests/testthat/testthat-problems.rds b/tests/testthat/testthat-problems.rds new file mode 100644 index 0000000..f8b6b4b Binary files /dev/null and b/tests/testthat/testthat-problems.rds differ diff --git a/vignettes/rgeoda_tutorial.Rmd b/vignettes/rgeoda_tutorial.Rmd index 2433f05..94823e0 100644 --- a/vignettes/rgeoda_tutorial.Rmd +++ b/vignettes/rgeoda_tutorial.Rmd @@ -502,6 +502,13 @@ lisa_pvalues(qsa) lisa_clusters(qsa) ``` +### 4.8 Bivariate Local Moran + +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 + +```{r} +qsa <- local_bimoran(queen_w, guerry[c('Crm_prs', 'Litercy')]) +``` ## 5 Spatial Clustering