# 1.3 Spatial Rate Mapping

The spatial lag is a weighted sum of the values observed at neighboring locations since the non-neighbors are not included. A spatial rate smoother is a special case of a nonparametric rate estimator, based on the principle of locally weighted estimation.

Spatial rate mapping emphasizes broad spatial trends and is useful for identifying general features of the data. However, it is not useful for the analysis of spatial autocorrelation, since the smoothed rates are autocorrelated by construction. It is also not very useful for identifying outlying observations, since the values portrayed are really regional averages and not specific to an individual location.

For more information, please read <https://geodacenter.github.io/workbook/4d_weights_applications/lab4d.html#spatial-rate-smoothing>

**CONTENTS**

* spatial\_lag()
* spatial\_rate()
* spatial\_empiricalbayes()

## 1. spatial\_lag()

The spatially lagged variable is a weighted average of the values at neighboring observations.

### **Synopsis**

Short Version

```sql
float spatial_lag(numeric val, bytea weights)
```

Full Version

```sql
float spatial_lag(numeric val, bytea weights, 
    boolean is_binary, boolean row_standardize, boolean include_diagonal)
```

### Arguments

| Name              | Type      | Description                                                                                                                                      |
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| val               | *numeric* | the numeric column that contains the values                                                                                                      |
| weights           | bytea     | the bytea column that stores the spatial weights information                                                                                     |
| is\_binary        | boolean   | <p>if the spatial weights is used as binary weights. Default: TRUE</p><p>(NOTE: for gal weights, is\_binary will be ignored and set as TRUE)</p> |
| row\_standardize  | boolean   | if use row-standardized weights. Default: TRUE                                                                                                   |
| include\_diagonal | boolean   | <p>if include diagonal of spatial weights. Default: FALSE</p><p>(NOTE: for kernel weights, please specify include\_diagonal=TRUE)</p>            |

### Example

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

    spatial_lag     
--------------------
    1.4625580352375
        1.524297299
  0.637481285083333
    ...
```

## 2. spatial\_rate()

In spatial rate smoothing, different spatial definitions of neighbors and/or different weights applied to those neighbors (e.g., contiguity weights, inverse distance weights, or kernel weights).&#x20;

### **Synopsis**

```sql
float spatial_rate(numeric event_variable, numeric base_variable, bytea weights)
```

### Example

```sql
SELECT spatial_rate(hr60::real, po60::real, queen_w) OVER() FROM natregimes;

    spatial_rate     
---------------------
                   0
                   0
                   0
                   0
   0.775047434799273
    4.49184458695377
    2.84060915923291
    ...
```

## 3. spatial\_eb()

Spatial Empirical Bayes (EB) Smoothing operates in the same way as the standard Empirical Bayes smoother, except that the reference rate is computed for a spatial window for each individual observation, rather than taking the same overall reference rate for all. This only works well for larger data sets, when the window (as defined by the spatial weights) is large enough to allow for effective smoothing.

For more information, please read <https://geodacenter.github.io/workbook/4d_weights_applications/lab4d.html#spatial-rate-smoothing>

### **Synopsis**

```sql
float spatial_eb(numeric event_variable, numeric base_variable, bytea weights)
```

### Example

```sql
SELECT spatial_eb(hr60::real, po60::real, queen_w) OVER() FROM natregimes;

      spatial_eb      
----------------------
 2.14167515161919e-05
 5.66145876362217e-06
 4.00998298627383e-05
 4.71962974310082e-05
 3.04083910095772e-05
 0.000343631582463113
    ...
```
