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

Result of `Spatex.ESDA.join_counts/3`: binary join counts with a Yates-corrected chi-square
test and permutation inference. Field names follow PySAL's `esda.Join_Counts`.

  * `j` - number of joins; `bb`, `ww`, `bw` - black-black, white-white and black-white joins.
  * `crosstab` / `expected` - the observed and expected 2x2 tables `[[ww, wb], [bw, bb]]`
    (focal rows, neighbor columns); entries are halves of directed counts.
  * `chi2`, `chi2_p`, `chi2_dof` - `scipy.stats.chi2_contingency` with its default Yates
    correction.
  * `autocorr_pos = bb + ww`, `autocorr_neg = bw`.

Permutation fields are `nil` when `permutations: 0`, and the `sim_*` vectors are also `nil`
with `keep_simulations: false`. `sim_autocurr_pos` and `sim_autocurr_neg` keep PySAL's
spelling. The `p_sim_*` values are upper-tail, not folded: `(count(sim >= observed) + 1) / (P + 1)`.

With `keep_simulations: :tensor`, each `sim_*` vector is an `Nx.Tensor` of type `{:f, 64}` and
shape `{permutations}` instead of a list.

`sim_autocorr_chi2` deviates from PySAL on purpose: esda divides both squared deviations
by the squared mean simulated positive autocorrelation (a bug); Spatex reports the survival
function (one degree of freedom) of the Pearson statistic
`(pos - mean_pos)^2 / mean_pos + (neg - mean_neg)^2 / mean_neg`.

# `t`

```elixir
@type t() :: %Spatex.ESDA.JoinCounts{
  autocorr_neg: float(),
  autocorr_pos: float(),
  bb: float(),
  bw: float(),
  chi2: value(),
  chi2_dof: float(),
  chi2_p: value(),
  crosstab: table(),
  expected: table(),
  j: float(),
  max_bb: float() | nil,
  max_bw: float() | nil,
  mean_bb: float() | nil,
  mean_bw: float() | nil,
  min_bb: float() | nil,
  min_bw: float() | nil,
  n: pos_integer(),
  p_sim_autocorr_neg: float() | nil,
  p_sim_autocorr_pos: float() | nil,
  p_sim_bb: float() | nil,
  p_sim_bw: float() | nil,
  p_sim_chi2: float() | nil,
  permutations: non_neg_integer(),
  seed: non_neg_integer() | nil,
  sim_autocorr_chi2: value() | nil,
  sim_autocurr_neg: [float()] | Nx.Tensor.t() | nil,
  sim_autocurr_pos: [float()] | Nx.Tensor.t() | nil,
  sim_bb: [float()] | Nx.Tensor.t() | nil,
  sim_bw: [float()] | Nx.Tensor.t() | nil,
  sim_chi2: [float()] | Nx.Tensor.t() | nil,
  ww: float()
}
```

# `table`

```elixir
@type table() :: [[float()]]
```

# `value`

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

---

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