> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getis-Ord Scala Object

### gLocal

Performs the Gi or Gi\* statistic on the x column of the dataframe.

```scala theme={"system"}
def gLocal(
      dataframe: DataFrame,
      x: String,
      weights: String = "weights",
      permutations: Int = 0,
      star: Boolean = false,
      islandWeight: Double = 0.0): DataFrame =
```

<ParamField path="dataframe" type="DataFrame">
  the dataframe to perform the G statistic on
</ParamField>

<ParamField path="x" type="String">
  The column name we want to perform hotspot analysis on
</ParamField>

<ParamField path="weights" type="String">
  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 row, excluding the neighbors/weights column itself).
     You can use `wherobots.weighing.add_distance_band_column` to generate this column in the required format.
</ParamField>

<ParamField path="permutations" type="Int">
  Not used. Permutation tests are not supported yet. The number of permutations to use for the significance test.
</ParamField>

<ParamField path="star" type="Boolean">
  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.
</ParamField>

<ParamField path="islandWeight" type="Double">
  Not used. The weight for the simulated neighbor used for records without a neighbor in perm tests
</ParamField>

### Returns

A DataFrame with the original columns plus the following additional columns:

<ResponseField name="G" type="Double">
  The calculated local G or G\* statistic.
</ResponseField>

<ResponseField name="E[G]" type="Double">
  The expected value of G/G\* under spatial randomness.
</ResponseField>

<ResponseField name="V[G]" type="Double">
  The variance of G/G\* under spatial randomness.
</ResponseField>

<ResponseField name="Z" type="Double">
  The Z-score (standard score) for the statistic.
</ResponseField>

<ResponseField name="P" type="Double">
  The p-value (significance) derived from the Z-score.
</ResponseField>

## Usage Examples

```scala theme={"system"}
import org.apache.sedona.stats.clustering.GetisOrd

// Example usage
val result = GetisOrd.gLocal(dataframe, epsilon, minPts)
```
