Title: | R Library for Spatial Data Analysis |
---|---|
Description: | 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>. |
Authors: | Xun Li [aut, cre], Luc Anselin [aut] |
Maintainer: | Xun Li <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.10-4 |
Built: | 2024-10-24 09:16:03 UTC |
Source: | https://github.com/cranhaven/cranhaven.r-universe.dev |
Override the as.data.frame function for rgeoda instance
## S3 method for class 'geoda' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
## S3 method for class 'geoda' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
A rgeoda object |
row.names |
NULL or a character vector giving the row names for the data frame. Missing values are not allowed. |
optional |
optional parameters |
... |
other arguments passed to methods |
A data.frame object
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)
as.geoda(obj, with_table = TRUE)
obj |
An instance of 'sf' or 'sp' object |
with_table |
A boolean flag indicates if table is copied from sf object to create geoda object. Default is TRUE |
An instance of geoda-class
Convert a GeoDa spatial weights object to a Matrix object
## S3 method for class 'Weight' as.matrix(x, rownames = NULL, rownames.value = NULL, ...)
## S3 method for class 'Weight' as.matrix(x, rownames = NULL, rownames.value = NULL, ...)
x |
A weights object |
rownames |
optional, a single column name or column number to use as the rownames in the returned matrix. If TRUE the key of the data.table will be used if it is a single column, otherwise the first column in the data.table will be used. |
rownames.value |
optional, a vector of values to be used as the rownames in the returned matrix. It must be the same length as nrow(x). |
... |
Required to be present because the generic 'as.matrix' generic has it. Arguments here are not currently used or passed on by this method. |
A matrix object
The automatic zoning procedure (AZP) was initially outlined in Openshaw (1977) as a way to address some of the consequences of the modifiable areal unit problem (MAUP). In essence, it consists of a heuristic to find the best set of combinations of contiguous spatial units into p regions, minimizing the within sum of squares as a criterion of homogeneity. The number of regions needs to be specified beforehand.
azp_greedy( p, w, df, bound_variable = data.frame(), min_bound = 0, inits = 0, initial_regions = vector("numeric"), scale_method = "standardize", distance_method = "euclidean", random_seed = 123456789, rdist = numeric() )
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, rdist = numeric() )
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. |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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, rdist = numeric() )
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, rdist = numeric() )
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. |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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, rdist = numeric() )
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, rdist = numeric() )
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. |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Create an empty weights
create_weights(num_obs)
create_weights(num_obs)
num_obs |
The number of observations for this empty weights |
An instance of Weight-class
Create a distance-based weights
distance_weights( sf_obj, dist_thres, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
distance_weights( sf_obj, dist_thres, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
sf_obj |
An sf (simple feature) object |
dist_thres |
A positive numeric value of distance threshold |
power |
(optional) The power (or exponent) of a number indicates how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) dist_thres <- min_distthreshold(guerry) dist_w <- distance_weights(guerry, dist_thres) summary(dist_w)
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) dist_thres <- min_distthreshold(guerry) dist_w <- distance_weights(guerry, dist_thres) summary(dist_w)
The function to compute EB Rate from an event variable and a base variable.
eb_rates(df)
eb_rates(df)
df |
A data frame with two selected variable: one is "event", anothor is "base" variable. E.g. guerry[c("hr60", "po60")] |
A data.frame with two columns "EB Rate" and "IsNull".
## Not run: library(sf) nat <- st_read("natregimes.shp") ebr <- eb_rates(nat[c("HR60", "PO60")]) ebr ## End(Not run)
## Not run: library(sf) nat <- st_read("natregimes.shp") ebr <- eb_rates(nat[c("HR60", "PO60")]) ebr ## End(Not run)
Create a distance-based weights
gda_distance_weights( geoda_obj, dist_thres, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
gda_distance_weights( geoda_obj, dist_thres, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
geoda_obj |
An instance of geoda-class |
dist_thres |
A positive numeric value of distance threshold |
power |
(optional) The power (or exponent) of a number indicates how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
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 )
gda_kernel_knn_weights( geoda_obj, k, kernel_method, adaptive_bandwidth = TRUE, use_kernel_diagonals = FALSE, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
geoda_obj |
An instance of geoda |
k |
a positive integer number for k-nearest neighbors |
kernel_method |
a string value, which has to be one of 'triangular', 'uniform', 'epanechnikov', 'quartic', 'gaussian' |
adaptive_bandwidth |
(optional) TRUE (default) or FALSE: TRUE use adaptive bandwidth calculated using distance of k-nearest neithbors, FALSE use max distance of all observation to their k-nearest neighbors |
use_kernel_diagonals |
(optional) FALSE (default) or TRUE, apply kernel on the diagonal of weights matrix |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
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 )
gda_kernel_weights( geoda_obj, bandwidth, kernel_method, use_kernel_diagonals = FALSE, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
geoda_obj |
An instance of geoda-class |
bandwidth |
A positive numeric value of bandwidth |
kernel_method |
a string value, which has to be one of 'triangular', 'uniform', 'epanechnikov', 'quartic', 'gaussian' |
use_kernel_diagonals |
(optional) FALSE (default) or TRUE, apply kernel on the diagonal of weights matrix |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
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 )
gda_knn_weights( geoda_obj, k, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
geoda_obj |
An instance of geoda |
k |
a positive integer number for k-nearest neighbors |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- geoda_open(guerry_path) knn6_w <- gda_knn_weights(guerry, 6) summary(knn6_w) ## End(Not run)
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- geoda_open(guerry_path) knn6_w <- gda_knn_weights(guerry, 6) summary(knn6_w) ## End(Not run)
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)
gda_min_distthreshold(geoda_obj, is_arc = FALSE, is_mile = TRUE)
geoda_obj |
An instance of geoda-class |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, if 'is_arc' option is TRUE, then 'is_mile' will set distance unit to 'mile' or 'km'. |
A numeric value of minimum threshold of distance
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 )
gda_queen_weights( geoda_obj, order = 1, include_lower_order = FALSE, precision_threshold = 0 )
geoda_obj |
An object of [geoda] class |
order |
(Optional) Order of contiguity |
include_lower_order |
(Optional) Whether or not the lower order neighbors should be included in the weights structure |
precision_threshold |
(Optional) The precision of the underlying shape file is insufficient to allow for an exact match of coordinates to determine which polygons are neighbors |
An instance of Weight-class
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- geoda_open(guerry_path) queen_w <- gda_queen_weights(guerry) summary(queen_w) ## End(Not run)
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- geoda_open(guerry_path) queen_w <- gda_queen_weights(guerry) summary(queen_w) ## End(Not run)
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 )
gda_rook_weights( geoda_obj, order = 1, include_lower_order = FALSE, precision_threshold = 0 )
geoda_obj |
An object of [geoda] class |
order |
(Optional) Order of contiguity |
include_lower_order |
(Optional) Whether or not the lower order neighbors should be included in the weights structure |
precision_threshold |
(Optional) The precision of the underlying shape file is insufficient to allow for an exact match of coordinates to determine which polygons are neighbors |
An instance of Weight-class
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- geoda_open(guerry_path) rook_w <- gda_rook_weights(guerry) summary(rook_w) ## End(Not run)
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- geoda_open(guerry_path) rook_w <- gda_rook_weights(guerry) summary(rook_w) ## End(Not run)
Create an instance of geoda-class by reading from an ESRI Shapefile dataset.
geoda_open(ds_path)
geoda_open(ds_path)
ds_path |
(character) The path of the spatial dataset |
An instance of geoda-class
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
'geoda' is a RefClass that wraps the C++ GeoDa class (via p_GeoDa defines in rgeoda.R)
gda
The pointer to the instance of p_GeoDa-class
map_type
The map type, could be either Point or Polygon
n_cols
The number of columns
n_obs
The number of observations
field_names
A string vector of field names
field_types
A string vector of field types (integer, real, string)
GetFieldNames(...)
Get the field names of all columns
GetFieldTypes(...)
Get the field types (integer, real, string) of all columns
GetIntegerCol(col_name)
Get the integer values from a column
GetMapType(...)
Get the map type
GetNumCols(...)
Get the number of columns
GetNumObs(...)
Get the number of observations
GetPointer()
Get the C++ object pointer (internally used)
GetRealCol(col_name)
Get the real values from a column
GetUndefinedVals(col_name)
Get the undefined flags from a column
initialize(o_gda)
Constructor with a geoda object (internally used)
Get neighbors for idx-th observation, idx starts from 1
get_neighbors(gda_w, idx)
get_neighbors(gda_w, idx)
gda_w |
A Weight object |
idx |
A value indicates idx-th observation, idx start from 1 |
A numeric vector of the neighbor indices, which start from 1
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
Get the associated weights values of neighbors for idx-th observation
get_neighbors_weights(gda_w, idx)
get_neighbors_weights(gda_w, idx)
gda_w |
A Weight object |
idx |
A value indicates idx-th observation, idx start from 1 |
A numeric vector of the neighbor indices, which start from 1
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
Check if weights matrix has isolates, or if any observation has no neighbors
has_isolates(gda_w)
has_isolates(gda_w)
gda_w |
A Weight object |
A boolean value indicates if weights matrix is symmetric
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) has_isolates(queen_w) ## End(Not run)
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) has_isolates(queen_w) ## End(Not run)
Hinge15 breaks data into 6 groups like box plot groups (Lower outlier, < 25
hinge15_breaks(df)
hinge15_breaks(df)
df |
A data frame with selected variable. E.g. guerry["Crm_prs"] |
A vector of numeric values of computed breaks
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) hinge15_breaks(guerry['Crm_prs'])
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) hinge15_breaks(guerry['Crm_prs'])
Hinge30 breaks data into 6 groups like box plot groups (Lower outlier, < 25
hinge30_breaks(df)
hinge30_breaks(df)
df |
A data frame with selected variable. E.g. guerry["Crm_prs"] |
A vector of numeric values of computed breaks
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) hinge30_breaks(guerry['Crm_prs'])
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) hinge30_breaks(guerry['Crm_prs'])
Check if weights matrix is symmetric
is_symmetric(gda_w)
is_symmetric(gda_w)
gda_w |
A Weight object |
A boolean value indicates if weights matrix is symmetric
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) is_symmetric(queen_w) ## End(Not run)
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) is_symmetric(queen_w) ## End(Not run)
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)
join_count_ratio(clusters, w)
clusters |
A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) |
w |
An instance of Weight class |
A data.frame with names "Cluster", "N", "Neighbors", "Join Count", "Ratio"
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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 )
kernel_knn_weights( sf_obj, k, kernel_method, adaptive_bandwidth = TRUE, use_kernel_diagonals = FALSE, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
sf_obj |
An sf (simple feature) object |
k |
a positive integer number for k-nearest neighbors |
kernel_method |
a string value, which has to be one of 'triangular', 'uniform', 'epanechnikov', 'quartic', 'gaussian' |
adaptive_bandwidth |
(optional) TRUE (default) or FALSE: TRUE use adaptive bandwidth calculated using distance of k-nearest neithbors, FALSE use max distance of all observation to their k-nearest neighbors |
use_kernel_diagonals |
(optional) FALSE (default) or TRUE, apply kernel on the diagonal of weights matrix |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) adptkernel_w = kernel_knn_weights(guerry, 6, "uniform") summary(adptkernel_w)
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) adptkernel_w = kernel_knn_weights(guerry, 6, "uniform") summary(adptkernel_w)
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 )
kernel_weights( sf_obj, bandwidth, kernel_method, use_kernel_diagonals = FALSE, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
sf_obj |
An sf (simple feature) object |
bandwidth |
A positive numeric value of bandwidth |
kernel_method |
a string value, which has to be one of 'triangular', 'uniform', 'epanechnikov', 'quartic', 'gaussian' |
use_kernel_diagonals |
(optional) FALSE (default) or TRUE, apply kernel on the diagonal of weights matrix |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) bandwidth <- min_distthreshold(guerry) kernel_w <- kernel_weights(guerry, bandwidth, kernel_method = "uniform") summary(kernel_w)
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) bandwidth <- min_distthreshold(guerry) kernel_w <- kernel_weights(guerry, bandwidth, kernel_method = "uniform") summary(kernel_w)
Create a k-nearest neighbors based spatial weights
knn_weights( sf_obj, k, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
knn_weights( sf_obj, k, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
sf_obj |
An sf (simple feature) object |
k |
a positive integer number for k-nearest neighbors |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
An instance of Weight-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) knn6_w <- knn_weights(guerry, 6) summary(knn6_w)
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) knn6_w <- knn_weights(guerry, 6) summary(knn6_w)
Get Bonferroni bound value based on current LISA computation and current significat p-value
lisa_bo(gda_lisa, current_p)
lisa_bo(gda_lisa, current_p)
gda_lisa |
An instance of LISA object |
current_p |
A value of current siginificant p-value |
A numeric value of Bonferroni bound
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get the local cluster indicators returned from LISA computation.
lisa_clusters(gda_lisa, cutoff = 0)
lisa_clusters(gda_lisa, cutoff = 0)
gda_lisa |
An instance of LISA object |
cutoff |
A value of cutoff for significance p-values to filter not-significant clusters, default=0.0, means not used |
A numeric vector of LISA cluster indicator
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get the cluster colors of LISA computation.
lisa_colors(gda_lisa)
lisa_colors(gda_lisa)
gda_lisa |
An instance of LISA object |
A string vector of cluster colors
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get False Discovery Rate value based on current LISA computation and current significant p-value
lisa_fdr(gda_lisa, current_p)
lisa_fdr(gda_lisa, current_p)
gda_lisa |
An instance of LISA object |
current_p |
A value of current siginificant p-value |
A numeric vector of False Discovery Rate
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get cluster labels of LISA computation.
lisa_labels(gda_lisa)
lisa_labels(gda_lisa)
gda_lisa |
An instance of LISA object |
A string vector of cluster labels
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get numbers of neighbors for all observations
lisa_num_nbrs(gda_lisa)
lisa_num_nbrs(gda_lisa)
gda_lisa |
An instance of LISA object |
A numeric vector of the number of neighbors
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get the local pseudo-p values of significance returned from LISA computation.
lisa_pvalues(gda_lisa)
lisa_pvalues(gda_lisa)
gda_lisa |
An instance of LISA object |
A numeric vector of pseudo-p values of local spatial autocorrelation
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get the local spatial autocorrelation values returned from LISA computation
lisa_values(gda_lisa)
lisa_values(gda_lisa)
gda_lisa |
An instance of LISA object |
A numeric vector of local spatial autocorrelation
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
A LISA-class that wrappers the statistics of LISA computation
gda_lisa
An object of GeoDaLISA
p_vals
The pseudo-p values of significance of LISA computation
c_vals
The cluster indicators of LISA computation
lisa_vals
The local spatial autocorrelation values of LISA computation
nn_vals
The number of neighbors of every observations in LISA computation
labels
The cluster labels of LISA
colors
The cluster colors (HEX format) of LISA
GetBO(current_p)
Get the Bonferroni bound value
GetClusterIndicators()
Get the local cluster indicators returned from LISA computation.
GetColors()
Get the cluster colors of LISA computation.
GetFDR(current_p)
Get the False Discovery Rate value
GetLISAValues()
Get the local spatial autocorrelation values returned from LISA computation.
GetLabels()
Get the cluster labels of LISA computation.
GetLocalSignificanceValues()
Get the local pseudo-p values of significance returned from LISA computation.
GetNumNeighbors()
Get the number of neighbors of every observations in LISA computation.
Run()
Call to run LISA computation
SetPermutations(num_perm)
Set the number of permutations for the LISA computation
SetSignificanceCutoff(cutoff)
Set the cutoff value of significance values
SetThreads(num_threads)
Set the number of CPU threads for the LISA computation
initialize(lisa_obj)
Constructor with a LISA object (internally used)
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 )
local_bijoincount( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with two selected variable. E.g. guerry[c("TopCrm", "InvCrm")] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) guerry["InvCrm"] <- 1 - guerry[["TopCrm"]] lisa <- local_bijoincount(queen_w, guerry[c("TopCrm", "InvCrm")]) clsts<- lisa_clusters(lisa) clsts
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) guerry["InvCrm"] <- 1 - guerry[["TopCrm"]] lisa <- local_bijoincount(queen_w, guerry[c("TopCrm", "InvCrm")]) clsts<- lisa_clusters(lisa) clsts
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 )
local_bimoran( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with two selected variable. E.g. guerry[c('Crm_prs','Litercy')] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_bimoran(queen_w, guerry[c('Crm_prs','Litercy')]) lms <- lisa_values(lisa) lms
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
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 )
local_g( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variable only. E.g. guerry["Crm_prs"] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_g(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_g(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
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 )
local_geary( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variable only. E.g. guerry["Crm_prs"] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_geary(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_geary(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
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 )
local_gstar( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variable only. E.g. guerry["Crm_prs"] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_gstar(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_gstar(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
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 )
local_joincount( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variable only. E.g. guerry["Crm_prs"] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_joincount(queen_w, guerry['TopCrm']) clsts<- lisa_clusters(lisa) clsts
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_joincount(queen_w, guerry['TopCrm']) clsts<- lisa_clusters(lisa) clsts
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 )
local_moran( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with only selected variable. E.g. guerry["Crm_prs"] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_moran(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_moran(queen_w, guerry["Crm_prs"]) lms <- lisa_values(lisa) lms
The function to apply local 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 )
local_moran_eb( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with two selected variable: one is "event", anothor is "base" variable. E.g. guerry[c("hr60", "po60")] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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 )
local_multigeary( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variables only. E.g. guerry["Crm_prs"] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) 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
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')] lisa <- local_multigeary(queen_w, data) lms <- lisa_clusters(lisa) lms
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 )
local_multijoincount( w, df, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variables only. E.g. guerry[c("TopCrm", "TopWealth", "TopLit")] |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_multijoincount(queen_w, guerry[c('TopWealth','TopWealth', 'TopLit')]) clsts <- lisa_clusters(lisa) clsts
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_multijoincount(queen_w, guerry[c('TopWealth','TopWealth', 'TopLit')]) clsts <- lisa_clusters(lisa) clsts
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 )
local_multiquantilelisa( w, df, k, q, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variables only. E.g. guerry[c("TopCrm", "TopWealth", "TopLit")] |
k |
A vector of "k" values indicate the number of quantiles for each variable. Value range e.g. [1, 10] |
q |
A vector of "q" values indicate which quantile or interval for each variable used in local join count statistics. Value stars from 1. |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) 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
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) 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
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 )
local_quantilelisa( w, df, k, q, permutations = 999, permutation_method = "complete", significance_cutoff = 0.05, cpu_threads = 6, seed = 123456789 )
w |
An instance of Weight object |
df |
A data frame with selected variable only. E.g. guerry["Crm_prs"] |
k |
A value indicates the number of quantiles. Value range e.g. [1, 10] |
q |
A value indicates which quantile or interval used in local join count statistics. Value stars from 1. |
permutations |
(optional) The number of permutations for the LISA computation |
permutation_method |
(optional) The permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default is 'complete'. |
significance_cutoff |
(optional) A cutoff value for significance p-values to filter not-significant clusters |
cpu_threads |
(optional) The number of cpu threads used for parallel LISA computation |
seed |
(optional) The seed for random number generator |
An instance of LISA-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_quantilelisa(queen_w, guerry["Crm_prs"], k=4, q=1) clsts <- lisa_clusters(lisa) clsts
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) lisa <- local_quantilelisa(queen_w, guerry["Crm_prs"], k=4, q=1) clsts <- lisa_clusters(lisa) clsts
Make spatially constrained clusters from spatially non-constrained clusters using the contiguity information from the input weights
make_spatial(clusters, w)
make_spatial(clusters, w)
clusters |
A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) |
w |
An instance of Weight class |
A vector of categorical values (cluster classification)
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get the number of maximum neighbors of spatial weights
max_neighbors(gda_w)
max_neighbors(gda_w)
gda_w |
A Weight object |
The number of maximum neighbors of spatial weights
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
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, rdist = numeric() )
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, rdist = numeric() )
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 |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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, rdist = numeric() )
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, rdist = numeric() )
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 |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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, rdist = numeric() )
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, rdist = numeric() )
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 |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
Get the number of mean neighbors of spatial weights
mean_neighbors(gda_w)
mean_neighbors(gda_w)
gda_w |
A Weight object |
The number of mean neighbors of spatial weights
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
Get the number of median neighbors of spatial weights
median_neighbors(gda_w)
median_neighbors(gda_w)
gda_w |
A Weight object |
The number of median neighbors of spatial weights
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
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)
min_distthreshold(sf_obj, is_arc = FALSE, is_mile = TRUE)
sf_obj |
An sf (simple feature) object |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations |
is_mile |
(optional) TRUE (default) or FALSE, if 'is_arc' option is TRUE, then 'is_mile' will set distance unit to 'mile' or 'km'. |
A numeric value of minimum threshold of distance
## Not run: library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) dist_thres <- min_distthreshold(guerry) dist_thres ## End(Not run)
## Not run: library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) dist_thres <- min_distthreshold(guerry) dist_thres ## End(Not run)
Get the number of minimum neighbors of spatial weights
min_neighbors(gda_w)
min_neighbors(gda_w)
gda_w |
A Weight object |
The number of minimum neighbors of spatial weights
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
Natural Breaks group data whose boundaries are set where there are relatively big differences.
natural_breaks(k, df)
natural_breaks(k, df)
k |
A numeric value indicates how many breaks |
df |
A data frame with selected variable. E.g. guerry["Crm_prs"] |
A vector of numeric values of computed breaks
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) natural_breaks(k=5, guerry['Crm_prs'])
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) natural_breaks(k=5, guerry['Crm_prs'])
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 )
neighbor_match_test( df, k, scale_method = "standardize", distance_method = "euclidean", power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
df |
A subset of sf object with selected variables. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")] |
k |
a positive integer number for k-nearest neighbors searching. |
scale_method |
(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization). |
distance_method |
(optional) The type of distance metrics used to measure the distance between input data. Options are 'euclidean', 'manhattan'. Default is 'euclidean'. |
power |
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication. |
is_inverse |
(optional) FALSE (default) or TRUE, apply inverse on distance value. |
is_arc |
(optional) FALSE (default) or TRUE, compute arc distance between two observations. |
is_mile |
(optional) TRUE (default) or FALSE, convert distance unit from mile to km. |
A data.frame with two columns "Cardinality" and "Probability".
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')] nbr_test <- neighbor_match_test(data, 6) nbr_test
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')] nbr_test <- neighbor_match_test(data, 6) nbr_test
p_GeoDa class is a RefClass that wraps the C++ 'GeoDa' class. See C++ functions in rcpp_rgeoda.cpp
p_GeoDaTable class is a RefClass that wraps the C++ 'GeoDaTable' class. See C++ functions in rcpp_rgeoda.cpp
p_GeoDaWeight class is a RefClass that wraps the C++ GeoDaWeight class. See C++ functions in rcpp_weights.cpp
p_LISA class is a RefClass that wraps the C++ LISA class. See C++ functions in rcpp_lisa.cpp
Percentile breaks data into 6 groups: the lowest 1 10-50
percentile_breaks(df)
percentile_breaks(df)
df |
A data frame with selected variable. E.g. guerry["Crm_prs"] |
A vector of numeric values of computed breaks
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) percentile_breaks(guerry['Crm_prs'])
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) percentile_breaks(guerry['Crm_prs'])
Quantile breaks data into groups that each have the same number of observations
quantile_breaks(k, df)
quantile_breaks(k, df)
k |
A numeric value indicates how many breaks |
df |
A data frame with selected variable. E.g. guerry["Crm_prs"] |
A vector of numeric values of computed breaks
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) quantile_breaks(k=5, guerry['Crm_prs'])
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) quantile_breaks(k=5, guerry['Crm_prs'])
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 )
queen_weights( sf_obj, order = 1, include_lower_order = FALSE, precision_threshold = 0 )
sf_obj |
An sf (simple feature) object |
order |
(Optional) Order of contiguity |
include_lower_order |
(Optional) Whether or not the lower order neighbors should be included in the weights structure |
precision_threshold |
(Optional) The precision of the underlying shape file is insufficient to allow for an exact match of coordinates to determine which polygons are neighbors |
An instance of Weight-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) summary(queen_w)
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) summary(queen_w)
Create a spatial weights object from a .GAL file
read_gal(file_path, id_vec = c())
read_gal(file_path, id_vec = c())
file_path |
The file paht of the .GAL file |
id_vec |
The id_vec is the id values used in the .GAL file. Default is empty. |
A weights object
Create a spatial weights object from a .GWT file
read_gwt(file_path, id_vec = c())
read_gwt(file_path, id_vec = c())
file_path |
The file paht of the .GWT file |
id_vec |
The id_vec is the id values used in the .GWT file. Default is empty. |
A weights object
Create a spatial weights object from a .SWM file
read_swm(file_path, id_vec = numeric())
read_swm(file_path, id_vec = numeric())
file_path |
The file paht of the .SWM file |
id_vec |
The id_vec is the id values used in the .SWM file. e.g. c(0,1,2,3,...) |
A weights object
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, rdist = numeric() )
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, rdist = numeric() )
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 |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
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".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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 )
rook_weights( sf_obj, order = 1, include_lower_order = FALSE, precision_threshold = 0 )
sf_obj |
An sf (simple feature) object |
order |
(Optional) Order of contiguity |
include_lower_order |
(Optional) Whether or not the lower order neighbors should be included in the weights structure |
precision_threshold |
(Optional) The precision of the underlying shape file is insufficient to allow for an exact match of coordinates to determine which polygons are neighbors |
An instance of Weight-class
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) rook_w <- rook_weights(guerry) summary(rook_w)
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) rook_w <- rook_weights(guerry) summary(rook_w)
Save spatial weights to a file
save_weights(gda_w, id_variable, out_path, layer_name = "")
save_weights(gda_w, id_variable, out_path, layer_name = "")
gda_w |
A Weight object |
id_variable |
The id variable (a data.frame) that defines the unique value of each observation when saving a weights file |
out_path |
The path of an output weights file |
layer_name |
(optional) The name of the layer of input dataset |
A boolean value indicates if save successfully or failed
## Not run: 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') ## End(Not run)
## Not run: 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') ## End(Not run)
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", rdist = numeric() )
schc( k, w, df, method = "average", bound_variable = data.frame(), min_bound = 0, scale_method = "standardize", distance_method = "euclidean", rdist = numeric() )
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" |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) 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
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 <- schc(4, queen_w, data, "complete") guerry_clusters
Set neighbors for idx-th observation, idx starts from 1
set_neighbors(gda_w, idx, nbrs)
set_neighbors(gda_w, idx, nbrs)
gda_w |
A Weight object |
idx |
A value indicates idx-th observation, idx start from 1 |
nbrs |
A list indicates the neighbors of idx-th observation (id start from 1) |
## Not run: new_w <- create_weights(10) set_neighbors(new_w, 1, c(2,3)) update_weights(new_w) ## End(Not run)
## Not run: new_w <- create_weights(10) set_neighbors(new_w, 1, c(2,3)) update_weights(new_w) ## End(Not run)
Set neighbors and the associated weights values for idx-th observation, idx starts from 1
set_neighbors_with_weights(gda_w, idx, nbrs, wvals)
set_neighbors_with_weights(gda_w, idx, nbrs, wvals)
gda_w |
A Weight object |
idx |
A value indicates idx-th observation, idx start from 1 |
nbrs |
A list indicates the neighbors of idx-th observation (id start from 1) |
wvals |
A list indicates the associated weights values of the neighbors |
## Not run: new_w <- create_weights(10) set_neighbors(new_w, 1, c(2,3)) update_weights(new_w) ## End(Not run)
## Not run: new_w <- create_weights(10) set_neighbors(new_w, 1, c(2,3)) update_weights(new_w) ## End(Not run)
Create an instance of geoda-class from a 'sf' object returned from 'st_read()' function. NOTE: The table content is NOT used to create an instance of geoda-class.
sf_to_geoda(sf_obj, with_table = TRUE)
sf_to_geoda(sf_obj, with_table = TRUE)
sf_obj |
An instance of 'sf' object |
with_table |
A boolean flag indicates if table is copied from sf object to create geoda object. Default is TRUE. |
An instance of geoda-class
SKATER forms clusters by spatially partitioning data that has similar values for features of interest.
skater( k, w, df, bound_variable = data.frame(), min_bound = 0, scale_method = "standardize", distance_method = "euclidean", random_seed = 123456789, cpu_threads = 6, rdist = numeric() )
skater( k, w, df, bound_variable = data.frame(), min_bound = 0, scale_method = "standardize", distance_method = "euclidean", random_seed = 123456789, cpu_threads = 6, rdist = numeric() )
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 |
rdist |
(optional) The distance matrix (lower triangular matrix, column wise storage) |
A names list with names "Clusters", "Total sum of squares", "Within-cluster sum of squares", "Total within-cluster sum of squares", and "The ratio of between to total sum of squares".
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) 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
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 <- skater(4, queen_w, data) guerry_clusters
Create an instance of geoda-class from a 'sp' object. NOTE: The table content is NOT used to create an instance of geoda-class.
sp_to_geoda(sp_obj, with_table = TRUE)
sp_to_geoda(sp_obj, with_table = TRUE)
sp_obj |
An instance of 'sp' object |
with_table |
A boolean flag indicates if table is copied from sf object to create geoda object. Default is TRUE |
An instance of geoda-class
Compute the spatial lag for idx-th observation using selected variable and current weights matrix
spatial_lag(gda_w, df)
spatial_lag(gda_w, df)
gda_w |
A Weight object |
df |
A data frame with selected variable only. E.g. guerry["Crm_prs"] |
A data.frame with one column "Spatial Lag"
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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)
spatial_validation(sf_obj, clusters, w)
sf_obj |
An sf (simple feature) object |
clusters |
A cluster classification variable (categorical values from a dataframe or values returned from cluster functions) |
w |
An instance of Weight class |
A list with names "Is Spatially Constrained", "Fragmentation", "Join Count Ratio", "Compactness", and "Diameter".
## Not run: 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 ## End(Not run)
## Not run: 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 ## End(Not run)
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)
stddev_breaks(df)
df |
A data frame with selected variable. E.g. guerry["Crm_prs"] |
A vector of numeric values of computed breaks
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) stddev_breaks(guerry['Crm_prs'])
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) stddev_breaks(guerry['Crm_prs'])
Override the summary() function for spatial weights
## S3 method for class 'Weight' summary(object, ...)
## S3 method for class 'Weight' summary(object, ...)
object |
A Weight object |
... |
summary optional parameters |
A summary description of an instance of Weight-class
## Not run: library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) summary(queen_w) ## End(Not run)
## Not run: library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) summary(queen_w) ## End(Not run)
Update meta data of a spatial weights. This function can be used after calling 'set_neighbor()' function .
update_weights(gda_w)
update_weights(gda_w)
gda_w |
A Weight object |
## Not run: new_w <- create_weights(10) set_neighbors(new_w, 1, c(2,3)) update_weights(new_w) ## End(Not run)
## Not run: new_w <- create_weights(10) set_neighbors(new_w, 1, c(2,3)) update_weights(new_w) ## End(Not run)
A wrapper class for p_GeoDaWeight class
gda_w
An object of p_GeoDaWeight-class
is_symmetric
If weights matrix is symmetric
sparsity
Sparsity of weights matrix
min_neighbors
Minimum number of neighbors
max_neighbors
Maximum number of neighbors
num_obs
Number of observations
mean_neighbors
Mean number of neighbors
median_neighbors
Median number of neighbors
has_isolates
If the weights matrix has any isolates
GetNeighborWeights(idx)
Get weights values of neighbors for idx-th observation, idx starts from 0
GetNeighbors(idx)
Get neighbors for idx-th observation, idx starts from 0
GetPointer()
Get the C++ object pointer (internally used)
GetSparsity()
Get sparsity computed from weights matrix
HasIsolates()
Check if weights matrix has isolates, or if any observation has no neighbors
IsSymmetric()
Check if weights matrix is symmetric
SaveToFile(out_path, layer_name, id_name, id_values)
Save current spatial weights to a file.
out_path: The path of an output weights file
layer_name : The name of the layer of input dataset
id_name : The id name (or field name), which is an associated column
contains unique values, that makes sure that the weights are connected
to the correct observations in the data table.
id_values : The tuple of values of selected id_name (column/field)
SetNeighbors(idx, nbrs)
Set neighbors for one observation
SetNeighborsAndWeights(idx, nbrs, nbr_w)
Set neighbors with weights values for one observation
SpatialLag(values)
Compute spatial lag values for values of selected variable
Update(updateStats = TRUE)
Update the weights meta data
initialize(o_gda_w)
Constructor with a GeoDaWeight object (internally used)
Get sparsity (
weights_sparsity(gda_w)
weights_sparsity(gda_w)
gda_w |
A Weight object |
A numeric value of spatial weights sparsity
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) weights_sparsity(queen_w) ## End(Not run)
## Not run: guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) queen_w <- queen_weights(guerry) weights_sparsity(queen_w) ## End(Not run)