# statistics

This module contains functions to perform spatial statistics calculations.

## GETIS\_ORD\_QUADBIN <a href="#getis_ord_quadbin" id="getis_ord_quadbin"></a>

```sql
GETIS_ORD_QUADBIN(input, size, kernel)
```

**Description**

This function computes the Getis-Ord Gi\* statistic for each Quadbin index in the input array.

**Input parameters**

* `input`: `SUPER` input data with the indexes and values of the cells.
* `size`: `INT8` size of the Quadbin *k-ring* (distance from the origin). This defines the area around each index cell that will be taken into account to compute its Gi\* statistic.
* `kernel`: `VARCHAR` [kernel function](https://en.wikipedia.org/wiki/Kernel_\(statistics\)) to compute the spatial weights across the kring. Available functions are: uniform, triangular, quadratic, quartic and gaussian.

**Return type**

`SUPER`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.GETIS_ORD_QUADBIN(
    JSON_PARSE('[
        {"index": 5266443791933898751, "value": 51.0},
        {"index": 5266443803500740607, "value": 28.0},
        {"index": 5266443790415822847, "value": 19.0}
    ]'),
    3, 'gaussian'
);
-- [{"index":5266443791933898751,"gi":1.3606194139870578,"p_value":0.086817058065399522},{"index":5266443803500740607,"gi":-0.34633948719670504,"p_value":0.63545613599515272},{"index":5266443790415822847,"gi":-1.0142799267903513,"p_value":0.84477538488255133}]
```

{% endcode %}

## MORANS\_I\_QUADBIN <a href="#morans_i_quadbin" id="morans_i_quadbin"></a>

```sql
MORANS_I_QUADBIN(input, size, decay)
```

**Description**

This function computes the [Moran's I spatial autocorrelation](https://en.wikipedia.org/wiki/Moran%27s_I) from the input array of quadkey indexes.

**Input parameters**

* `input`: `SUPER` input data with the indexes and values of the cells.
* `size`: `INT8` size of the quadkey *k-ring* (distance from the origin). This defines the area around each index cell where the distance decay will be applied.
* `decay`: `VARCHAR` decay function to compute the [distance decay](https://en.wikipedia.org/wiki/Distance_decay). Available functions are: uniform, inverse, inverse\_square and exponential.

**Return type**

`FLOAT8`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.MORANS_I_QUADBIN(
    JSON_PARSE('[
        {"index": 5266443791927869439, "value": 51.0},
        {"index": 5266443791928131583, "value": 28.0},
        {"index": 5266443791928918015, "value": 19.0}
    ]'),
    3, 'exponential'
);
-- -0.2966571382680862
```

{% endcode %}

## P\_VALUE <a href="#p_value" id="p_value"></a>

```sql
P_VALUE(z_score)
```

**Description**

This function computes the p-value (two-tails test) of a given [z-score](https://en.wikipedia.org/wiki/Standard_score) assuming the population follows a normal distribution where the mean is 0 and the standard deviation is 1. The z-score is a measure of how many standard deviations below or above the population mean a value is. It gives you an idea of how far from the mean a data point is. The [p-value](https://en.wikipedia.org/wiki/P-value) is the probability that a randomly sampled point has a value at least as extreme as the point whose z-score is being tested.

**Input parameters**

* `z_score`: `FLOAT8` input data with the indexes and values of the cells.

**Return type**

`FLOAT8`

**Example**

{% code overflow="wrap" lineNumbers="true" %}

```sql
SELECT carto.P_VALUE(-2);
-- 0.04550012577451279
```

{% endcode %}


---

# 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://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/statistics.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.
