# 4.3 Bivariate Local Join Count

Bivariate or no-colocation local join count ([2019](https://geodacenter.github.io/workbook/6d_local_discrete/lab6d.html#ref-AnselinLi:18)) only works when two events cannot happen in the same location (e.g., a zoning classification, or a case-control design). It can be used to identify *negative* spatial autocorrelation, i.e., evidence of spatial outliers. For more information, please read [http://geodacenter.github.io/workbook/6a\_local\_auto/lab6a.html](https://geodacenter.github.io/workbook/6d_local_discrete/lab6d.html#bivariate-local-join-count-statistic)

## local\_bijoincount()

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

### Synopsis

Short version:

```sql
float[] local_bijoincount(real val1, numeric val2, bytea weights)
```

Full version:

```sql
float[] local_bijoincount(numeric val1, numeric val2, bytea weights,
    integer permutations, 
    character varying permutation_method,
    float significance_cutoff, 
    integer cpu_threads, 
    integer seed)
```

### Arguments

| Name                 | Type              | Description                                                                                                |
| -------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------- |
| val1                 | *numeric*         | the first numeric column that contains the binary values (e.g. 0 and 1) for LISA statistics                |
| val1                 | *numeric*         | the second numeric column that contains the binary values (e.g. 0 and 1) 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 {'local join count',  'pseudo-p value', 'number of neighbors'} |

{% hint style="info" %}
The results do NOT have 'category indicator'.
{% endhint %}

### Examples

Apply bivariate local join count statistics on the variable "death\_*dum" (dummy variable for death incidence, dataset '*[*deaths\_nd\_by*\_house](https://geodacenter.github.io/data-and-lab/snow/)'), and "1 - death\_dum" using distance-based weights "d20" (distance cutoff value = 20 meters):

* Create weights:

```sql
-- add a new column 'd20' first
-- ALTER TABLE deaths_nd_by_house ADD COLUMN d20 bytea
UPDATE deaths_nd_by_house SET d20 = w.distance_weights
FROM (
  SELECT 
    gid, 
    distance_weights(gid, ST_Transform(the_geom, 27700), 20.0) 
  OVER() FROM deaths_nd_by_house
) AS w 
WHERE deaths_nd_by_house.gid = w.gid
```

{% hint style="info" %}
When importing the dataset to PostgresSQL, the projection could be changed (e.g. using EPSG: 4326). In this example, we need to use **ST\_Transform**(geom, srid) to project the points from EPSG 4326 to EPSG 27700 (unit: meter) so that we can create distance weights using 20.0 meters as the cutoff value.
{% endhint %}

* apply local\_bijoincount()

```sql
SELECT local_bijoincount(death_dum, (1-death_dum), d20) OVER() FROM deaths_nd_by_house;

 local_joincount 
-----------------
 {0,-1,11}
 {0,-1,11}
 {0,-1,12}
 {0,-1,12}
 {7,0.009,14}
 {6,0.021,12}
 {7,0.005,13}
 {5,0.079,13}
 ...
```


---

# 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/4.2-bivariate-local-join-count.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.
