# 4.1 Local Neighbor Match Test

The local neighbor match test ([2020](https://geodacenter.github.io/workbook/6c_local_multi/lab6c.html#ref-AnselinLi:20)) is a method to identify significant locations by assessing the extent of overlap between k-nearest neighbors in geographical space and k-nearest neighbors in multi-attribute space. For more information, please read <https://geodacenter.github.io/workbook/6c_local_multi/lab6c.html#local-neighbor-match-test>

## neighbor\_match\_test()

{% hint style="info" %}
neighbor\_*match\_test*() is a PostgreSQL WINDOW function. Please call it  with an OVER clause.
{% endhint %}

### Synopsis

Short version:

```sql
float[] neighbor_match_test(geometry the_geom, anyarray vals, integer k)
```

Long version:

```sql
float[] neighbor_match_test(geometry the_geom, anyarray vals, integer k,
    character varying scale_method,
    character varying distance_method
)
```

Full version:

```sql
float[] neighbor_match_test(geometry the_geom, anyarray vals, integer k,
    character varying scale_method,
    character varying distance_method
    float power, 
    boolean is_inverse, 
    boolean is_arc
    boolean is_mile
)
```

### Arguments

| Name             | Type              | Description                                                                                                                                          |
| ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| the\_geom        | geometry          | the geometry column (only points and polygons are supported)                                                                                         |
| vals             | *anyarray*        | an array of numeric columns that contains the values for neighbor match test                                                                         |
| k                | integer           | k nearest neighbor for both attribute and geographical space                                                                                         |
| scale\_method    | character varying | the scaling method. Options are {'*raw*', '*standardize*', '*demean*', '*mad*', '*range\_standardize*', '*range\_adjust*'}. Default: '*standardize*' |
| distance\_method | character varying | the distance method. Options are {'*euclidean*', '*manhattan*'. Default: '*euclidean*'.                                                              |
| power            | float             | the power/exponent corresponds to the number of times the base (dist\_band) is used as a factor. Default: 1.                                         |
| is\_inverse      | boolean           | if apply inverse on distance value. Default: False.                                                                                                  |
| is\_arc          | boolean           | if compute arc distance between two observations. Default: FALSE.                                                                                    |
| is\_mile         | boolean           | if convert distance unit from mile to kilometer(KM). Default: TRUE.                                                                                  |

### Return

| Type     | Description                                                              |
| -------- | ------------------------------------------------------------------------ |
| float\[] | an array contains 2 values, which are {'*cardinality*', '*probability*'} |

{% hint style="info" %}
**cardinality**: the number of common neighbors for each location
{% endhint %}

### Examples

Apply local neighbor match test on 6 nearest neighbors of the variables \["hr60", "ue60"] (homicide and unemployment rate 1960 in [natregimes dataset](https://geodacenter.github.io/data-and-lab/natregimes/)):

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

```sql
SELECT neighbor_match_test(the_geom, ARRAY[hr60, ue60], 6) OVER() FROM natregimes;

   neighbor_match_test    
--------------------------
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {0,-1}
 {1,0.0115787398060671}
 {1,0.0115787398060671}
 ...
```

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xunli.gitbook.io/postgeoda/4.-lisa-multivariate/3.1-local-moran.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
