# Local Moran

Local indicators of spatial association or LISA is a class of local statistics that measure spatial association in sub-regions of the study region. They are often used to identify spatial outliers and local clusters.&#x20;

The Local Moran statistic was suggested in Anselin ([1995](http://geodacenter.github.io/workbook/6a_local_auto/lab6a.html#ref-Anselin:95)) as a way to identify local clusters and local spatial outliers. For more details, please read <http://geodacenter.github.io/workbook/6a_local_auto/lab6a.html>

## localMoran()

```sql
function localMoran(
    WeightResult w,
    Array val,
    Number permutations, 
    String permutation_method,
    NUmber significance_cutoff, 
    Number seed)
```

### Arguments

| Name                 | Type           | Description                                                                                                |
| -------------------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| w                    | *WeightResult* | the WeightResult object created from weights function                                                      |
| val                  | Array          | the values of a selected variable                                                                          |
| permutations         | Number         | the number of permutations for the LISA computation. Default: 999.                                         |
| permutation\_method  | String         | the permutation method used for the LISA computation. Options are 'complete', 'lookup'. Default: 'lookup'. |
| significance\_cutoff | Number         | the cutoff value for significance p-values to filter not-significant clusters. Default: 0.05.              |
| seed                 | Number         | the seed for random number generator used in LISA statistics. Default: 123456789.                          |

### Return

| Type       | Description                                                                                                                  |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
| LisaResult | The LisaResult object contains the results of LISA computation: *pvalues, clusters, lisa\_values, neighbors, labels, colors* |

**Examples**

{% tabs %}
{% tab title="Node.js" %}

```javascript
const jsgeoda = require('jsgeoda');
const fs = require('fs');

// load data
const data = fs.readFileSync('./data/natregimes.geojson').buffer;

// create jsgeoda instance
const geoda = await jsgeoda.New();

// load geojson in jsgeoda
const nat = geoda.readGeoJSON(data);

// create a queen contiguity weights
const w = geoda.getQueenWeights(nat);

// get HR60 values
const hr60 = geoda.getColumn(nat, "HR60");

// local moran statistics 
const lm = geoda.localMoran(w, hr60);


```

{% endtab %}

{% tab title="React" %}

```javascript
import React, { Component } from "react";
import ReactDOM from "react-dom";
import DeckGL from "@deck.gl/react";
import { GeoJsonLayer } from "@deck.gl/layers";
import { StaticMap } from "react-map-gl";
import jsgeoda from "jsgeoda";

// Set your mapbox access token here
const MAPBOX_TOKEN =
  "pk.eyJ1IjoibGl4dW45MTAiLCJhIjoiY2locXMxcWFqMDAwenQ0bTFhaTZmbnRwaiJ9.VRNeNnyb96Eo-CorkJmIqg";

// The geojson data
const DATA_URL = `https://webgeoda.github.io/data/natregimes.geojson`;

class App extends Component {
  constructor() {
    super();
    this.state = {
      mapId: "",
      layer: null,
      viewPort: {
        longitude: -100.4,
        latitude: 38.74,
        zoom: 2.5,
        maxZoom: 20
      }
    };
  }

  // load spatial data when mount this component
  loadSpatialData(geoda) {
    fetch(DATA_URL)
      .then((res) => res.arrayBuffer())
      .then((data) => {
        // load geojson in jsgeoda, an unique id (string) will be returned for further usage
        const nat = geoda.readGeoJSON(data);
        const w = geoda.getQueenWeights(nat);
        const hr60 = geoda.getColumn(nat, "HR60");
        const lm = geoda.localMoran(w, hr60, 999, "lookup");

        //const ue60 = geoda.get_col(nat, "UE60");
        //const nmt = geoda.neighbor_match_test(nat, 5, [hr60, ue60]);

        const lm_colors = lm.colors.map((c) =>
          c
            .toLowerCase()
            .match(/[0-9a-f]{2}/g)
            .map((x) => parseInt(x, 16))
        );
        // Viewport settings
        const view_port = geoda.get_viewport(
          nat,
          window.innerHeight,
          window.innerWidth
        );

        // Create GeoJsonLayer
        const layer = new GeoJsonLayer({
          id: "GeoJsonLayer",
          data: DATA_URL,
          filled: true,
          getFillColor: (f) => this.getFillColor(f, lm.clusters, lm_colors),
          stroked: true,
          pickable: true
        });

        // Trigger to draw map
        this.setState({
          mapId: nat,
          layer: layer,
          viewPort: view_port
        });
      });
  }

  componentDidMount() {
    // jsgeoda.New() function will create an instance from WASM
    jsgeoda.New().then((geoda) => {
      this.loadSpatialData(geoda);
    });
  }

  // Determine which color for which geometry
  getFillColor(f, clusters, colors) {
    const i = f.properties.POLY_ID - 1;
    const c = clusters[i];
    return colors[c];
  }

  render() {
    return (
      <div>
        <DeckGL
          initialViewState={this.state.viewPort}
          layers={[this.state.layer]}
          controller={true}
          getTooltip={({ object }) =>
            object && `${object.properties.NAME}: ${object.properties.HR60}`
          }
        >
          <StaticMap mapboxApiAccessToken={MAPBOX_TOKEN} />
        </DeckGL>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("root"));

```

{% endtab %}
{% endtabs %}

**Try it yourself in the playground (jsgeoda + deck.gl):**

{% embed url="<https://codesandbox.io/s/5lisaunivariate-zhhop>" %}


---

# 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/jsgeoda/local-spatial-autocorrelation/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.
