> For the complete documentation index, see [llms.txt](https://xunli.gitbook.io/jsgeoda/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xunli.gitbook.io/jsgeoda/choropleth_map/spatial-rate-mapping.md).

# 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>

## 1. spatialLag()

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

```sql
Array spatialLag(
    WeightResult w, 
    Array val,
    Boolean isBinary, 
    Boolean rowStandardize, 
    Boolean includeDiagonal)
```

### Arguments

| Name            | Type         | Description                                                                                                                                      |
| --------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| val             | Array        | the numeric values                                                                                                                               |
| weights         | WeightResult | the WeightResult object that stores the spatial weights information                                                                              |
| isBinary        | 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> |
| rowStandardize  | Boolean      | if use row-standardized weights. Default: TRUE                                                                                                   |
| includeDiagonal | Boolean      | <p>if include diagonal of spatial weights. Default: FALSE</p><p>(NOTE: for kernel weights, please specify include\_diagonal=TRUE)</p>            |

## 2. spatialRate()

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;

```sql
Array spatialRate(WeightResult w, Array eventVariable, Array baseVariable)
```

## 3. spatialEB()

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>

```sql
Array spatialEB(WeightResult w, Array eventVariable, Array baseVariable)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://xunli.gitbook.io/jsgeoda/choropleth_map/spatial-rate-mapping.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
