# `Spatex.ESDA.MoranLocal`
[🔗](https://github.com/CountlinkX-Solutions/spatex/blob/v0.2.1/lib/spatex/esda/moran_local.ex#L1)

Result of `Spatex.ESDA.moran_local/3` and `Spatex.ESDA.moran_local_bv/4`: local Moran's I
(LISA, `esda.Moran_Local` / `esda.Moran_Local_BV`).

Every per-site field is a list aligned with the graph's node order (`ids`); Explorer
conversion arrives with M5. Field names are PySAL's attributes in snake_case (`Is` is `is`,
`seI_sim` is `se_i_sim`, `EIc` is `ei_c`).

  * `is` - local statistic, `q` - quadrant (1 High-High, 2 Low-High, 3 Low-Low, 4 High-Low;
    2 and 3 swapped with `geoda_quads: true`), `z` - standardized values (ddof 0; `x` for the
    bivariate statistic, whose standardized `y` is `z_y`), `lag` - spatial lag of `z` (of
    `z_y` for the bivariate statistic).
  * `ei`, `vi`, `se_i` - expectation, variance and standard deviation under total
    randomization; `ei_c`, `vi_c` - conditional randomization moments (Sokal et al. 1998).
    They are `nil` for the bivariate statistic, as esda has no analytic moments for it.
  * `p_sim` - pseudo p-value of the conditional randomization (see `:alternative`), `sim` -
    the simulated statistics, one list of `permutations` values per site (esda's `rlisas`),
    `ei_sim`, `se_i_sim`, `vi_sim`, `z_sim`, `p_z_sim` - their moments and the one-tailed
    normal p-value of `z_sim`. All are `nil` with `permutations: 0`; with
    `keep_simulations: false`, `sim` and the moments are `nil` (as in esda) and only `p_sim`
    remains.

Islands: the statistic is `0`, and (as in esda) their `p_sim` is the smallest possible
`1 / (permutations + 1)` and `z_sim` is `:nan`. Non-finite floats are the atoms `:nan`,
`:infinity` and `:neg_infinity`.

With `keep_simulations: :tensor`, `sim` is an `Nx.Tensor` of type `{:f, 64}` and shape
`{n, permutations}` instead of nested lists.

# `t`

```elixir
@type t() :: %Spatex.ESDA.MoranLocal{
  alternative: atom(),
  ei: [value()] | nil,
  ei_c: [value()] | nil,
  ei_sim: [value()] | nil,
  geoda_quads: boolean(),
  ids: [term()] | nil,
  is: [value()],
  lag: [value()],
  n: pos_integer(),
  p_sim: [float()] | nil,
  p_z_sim: [value()] | nil,
  permutations: non_neg_integer(),
  q: [1..4],
  se_i: [value()] | nil,
  se_i_sim: [value()] | nil,
  seed: non_neg_integer() | nil,
  sim: [[float()]] | Nx.Tensor.t() | nil,
  vi: [value()] | nil,
  vi_c: [value()] | nil,
  vi_sim: [value()] | nil,
  z: [value()],
  z_sim: [value()] | nil,
  z_y: [value()] | nil
}
```

# `value`

```elixir
@type value() :: float() | :nan | :infinity | :neg_infinity
```

# `cluster_labels`

```elixir
@spec cluster_labels(t(), number()) :: [String.t()]
```

LISA cluster labels (`esda`'s `get_cluster_labels`).

A site is labelled by its quadrant (`"High-High"`, `"Low-High"`, `"Low-Low"`, `"High-Low"`)
when `p_sim < crit` (strictly), otherwise `"Insignificant"`. The labels follow `q` as
computed, so with `geoda_quads: true` the names of quadrants 2 and 3 are swapped, exactly as
in esda. Raises `ArgumentError` for a result computed with `permutations: 0`.

## Examples

    iex> m = %Spatex.ESDA.MoranLocal{q: [1, 3, 2], p_sim: [0.01, 0.2, 0.049], n: 3, permutations: 99}
    iex> Spatex.ESDA.MoranLocal.cluster_labels(m)
    ["High-High", "Insignificant", "Low-High"]
    iex> Spatex.ESDA.MoranLocal.cluster_labels(m, 0.5)
    ["High-High", "Low-Low", "Low-High"]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
