Skip to main content

g_local

Calculates the Getis-Ord Gi or Gi* statistic on the x column of the dataframe.
def g_local(dataframe: DataFrame, x: str, weights: str, permutations: int, star: bool, island_weight: float) -> DataFrame

Additional Information

For more information on the Getis-Ord functions see: “Getis-Ord functions. From the 1992 paper by Getis & Ord. Getis, A., & Ord, J. K. (1992). The analysis of spatial association by use of distance statistics. Geographical Analysis, 24(3), 189-206. https://doi.org/10.1111/j.1538-4632.1992.tb00261.x

Parameters

dataframe
DataFrame
required
the dataframe to perform the G statistic on
x
str
required
The column name we want to perform hotspot analysis on
weights
str
required
The column name containing the neighbors array. The array should be of type Array<Struct<value: T, neighbor: U>>, where each element is a Struct with two fields:
  1. value: The weight for the neighbor (e.g., spatial weight).
  2. neighbor: A Struct containing the data of the neighboring row (schema must match the parent DataFrame, excluding the weights column itself). You can use wherobots.weighing.add_distance_band_column to generate this column in the required format.
permutations
int
required
Not used. Permutation tests are not supported yet. The number of permutations to use for the
star
bool
required
Specifies whether to calculate the Getis-Ord Gi* statistic.
  • true: Calculates the Gi* statistic, which includes the focal observation (the row itself) in the local sum. When star=true, the weights array must include the focal observation as one of its own neighbors.
  • false: (Default) Calculates the G-statistic, which excludes the focal observation.
island_weight
float
required
Not used. The weight for the simulated neighbor used for records without a neighbor in perm testsPermutation testing is not yet implemented. Consequently, any parameter related to island_weight currently has no effect.

Returns

A DataFrame with the original columns plus the following additional columns:
G
Double
The calculated local G or G* statistic.
E[G]
Double
The expected value of G/G* under spatial randomness.
V[G]
Double
The variance of G/G* under spatial randomness.
Z
Double
The Z-score (standard score) for the statistic. Statistical significance (Z and P columns) is calculated using Z-scores derived from the theoretical expected value and variance under spatial randomness.
P
Double
The p-value (significance) derived from the Z-score. Statistical significance (Z and P columns) is calculated using Z-scores derived from the theoretical expected value and variance under spatial randomness.

Usage Examples

from getis_ord import *

# Example usage of g_local
result = g_local(dataframe=example_value, x=example_value, weights=example_value)