# 3.3 Local Getis-Ord G

The local Getis-Ord statistic is a ratio of the weighted average of the values in the neighboring locations to the sum of all values. It is called local g or local g\*, when not including the value at the location. In local g/g\*, a value larger than the mean (or, a positive value for a standardized z-value) suggests a High-High cluster or hot spot, a value smaller than the mean (or, negative for a z-value) indicates a Low-Low cluster or cold spot. For more information, please read: <https://geodacenter.github.io/workbook/6b_local_adv/lab6b.html#getis-ord-statistics>

{% hint style="info" %}
In contrast to the Local Moran and Local Geary statistics, the Getis-Ord approach does not consider spatial outliers.
{% endhint %}

**CONTENTS**

1. local\_g() and local\_gstar()

## local\_g(), local\_gstar()

{% hint style="info" %}
local\_g() or local\_gstar() is a PostgreSQL WINDOW function. Please call it  with an OVER clause.
{% endhint %}

### Synopsis

Short version:

```sql
float[] local_g(numeric val,  bytea weights)
```

```sql
float[] local_gstar(numeric val,  bytea weights)
```

Full version:

```sql
float[] local_g(numeric val,  bytea weights,
    integer permutations, 
    character varying permutation_method,
    float significance_cutoff, 
    integer cpu_threads, 
    integer seed)
```

```sql
float[] local_gstar(numeric val,  bytea weights,
    integer permutations, 
    character varying permutation_method,
    float significance_cutoff, 
    integer cpu_threads, 
    integer seed)
```

### Arguments

| Name                 | Type              | Description                                                                                                |
| -------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------- |
| val                  | *numeric*         | the numeric column that contains the values for LISA statistics                                            |
| weights              | bytea             | the bytea column that stores the spatial weights information                                               |
| permutations         | integer           | the number of permutations for the LISA computation. Default: 999.                                         |
| permutation\_method  | character varying | the permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default: 'lookup'. |
| significance\_cutoff | float             | the cutoff value for significance p-values to filter not-significant clusters. Default: 0.05.              |
| cpu\_threads         | integer           | the number of CPU threads used for parallel LISA computation. Default: 6.                                  |
| seed                 | integer           | the seed for random number generator used in LISA statistics. Default: 123456789.                          |

### Return

| Type     | Description                                                                                    |
| -------- | ---------------------------------------------------------------------------------------------- |
| float\[] | an array contains 3 values, which are {'lisa value', 'pseudo-p value' and 'cluster indicator'} |

### Examples

Apply local\_g on the variable "hr60" (homicide rate 1960 in [natregimes dataset](https://geodacenter.github.io/data-and-lab/natregimes/)) using queen contiguity weights "queen\_w":

{% hint style="info" %}
Please see chapter '[Contiguity Based Weights](https://xunli.gitbook.io/postgeoda/2.-spatial-weights/2.1-contiguity-based-weights)' for how to create a Queen contiguity weights.
{% endhint %}

```sql
SELECT local_g(hr60, queen_w) OVER() FROM natregimes;

            local_g             
--------------------------------
 {6.82727000829049e-05,0.086,0}
 {0.000180615019894871,0.289,0}
 {0.00010018844366193,0.075,0}
 ...
```

One can specify the arguments of local g using the full version of local\_g() function. For example, apply local moran statistics using 9,999 permutations, significance cutoff value 0.01:

```sql
SELECT local_g(
    hr60, queen_w, 9999, 'lookup', 0.01, 6, 123456789
) OVER() FROM natregimes;

             local_g             
---------------------------------
 {6.82727000829049e-05,0.0868,0}
 {0.000180615019894871,0.2858,0}
 {0.00010018844366193,0.0843,0}
 ...
```

### Cluster Indicators

The predefined values of the cluster indicators of local g/g\* are:

| Cluster indicator value | Description     | Color   |
| ----------------------- | --------------- | ------- |
| 0                       | Not significant | #eeeeee |
| 1                       | High-High       | #ff0000 |
| 2                       | Low-Low         | #0000ff |
| 3                       | Undefined Value | #464646 |
| 4                       | Isolated        | #999999 |

One can extract the cluster indicators and make a local g/g\* cluster map using the 'Color" values in the table above:

```sql
SELECT tmp.local_g[3] FROM (
    SELECT local_g(hr60, queen_w) OVER() FROM natregimes
) AS tmp;
```

Or by extracting the pseudo-p values to make a significance map:

```sql
SELECT tmp.local_g[2] FROM (
    SELECT local_g(hr60, queen_w) OVER() FROM natregimes
) AS tmp;
```
