esda.Join_Counts

class esda.Join_Counts(y, w, permutations=999, drop_islands=True)[source]

Binary Join Counts

Parameters:
yarray

binary variable measured across n spatial units

wW

spatial weights instance

permutationsint

number of random permutations for calculation of pseudo-p_values

Notes

Technical details and derivations can be found in [CO81].

Examples

>>> import numpy as np
>>> import libpysal
>>> w = libpysal.weights.lat2W(4, 4)
>>> y = np.ones(16)
>>> y[0:8] = 0
>>> np.random.seed(12345)
>>> from esda.join_counts import Join_Counts
>>> jc = Join_Counts(y, w)
>>> jc.bb
10.0
>>> jc.bw
4.0
>>> jc.ww
10.0
>>> jc.J
24.0
>>> len(jc.sim_bb)
999
>>> round(jc.p_sim_bb, 3)
0.003
>>> round(np.mean(jc.sim_bb), 3)
5.547
>>> np.max(jc.sim_bb)
10.0
>>> np.min(jc.sim_bb)
0.0
>>> len(jc.sim_bw)
999
>>> jc.p_sim_bw
1.0
>>> np.mean(jc.sim_bw)
12.811811811811811
>>> np.max(jc.sim_bw)
24.0
>>> np.min(jc.sim_bw)
7.0
>>> round(jc.chi2_p, 3)
0.004
>>> jc.p_sim_chi2
0.002
Attributes:
yarray

original variable

wW

original w object

permutationsint

number of permutations

bbfloat

number of black-black joins

wwfloat

number of white-white joins

bwfloat

number of black-white joins

Jfloat

number of joins

sim_bbarray

(if permutations>0) vector of bb values for permuted samples

p_sim_bbarray
(if permutations>0)

p-value based on permutations (one-sided) null: spatial randomness alternative: the observed bb is greater than under randomness

mean_bbfloat

average of permuted bb values

min_bbfloat

minimum of permuted bb values

max_bbfloat

maximum of permuted bb values

sim_bwarray

(if permutations>0) vector of bw values for permuted samples

p_sim_bwarray

(if permutations>0) p-value based on permutations (one-sided) null: spatial randomness alternative: the observed bw is greater than under randomness

mean_bwfloat

average of permuted bw values

min_bwfloat

minimum of permuted bw values

max_bwfloat

maximum of permuted bw values

chi2float

Chi-square statistic on contingency table for join counts

chi2_pfloat

Analytical p-value for chi2

chi2_dofint

Degrees of freedom for analytical chi2

crosstabDataFrame

Contingency table for observed join counts

expectedDataFrame

Expected contingency table for the null

p_sim_chi2float

p-value for chi2 under random spatial permutations

drop_islandsbool (default True)

Whether or not to preserve islands as entries in the adjacency list. By default, observations with no neighbors do not appear in the adjacency list. If islands are kept, they are coded as self-neighbors with zero weight. See libpysal.weights.to_adjlist().

__init__(y, w, permutations=999, drop_islands=True)[source]

Methods

__init__(y, w[, permutations, drop_islands])

by_col(df, cols[, w, inplace, pvalue, outvals])

Function to compute a Join_Count statistic on a dataframe

classmethod by_col(df, cols, w=None, inplace=False, pvalue='sim', outvals=None, **stat_kws)[source]

Function to compute a Join_Count statistic on a dataframe

Parameters:
dfpandas.DataFrame

a pandas dataframe with a geometry column

colsstr or list of str

name or list of names of columns to use to compute the statistic

wpysal weights object

a weights object aligned with the dataframe. If not provided, this is searched for in the dataframe’s metadata

inplacebool

a boolean denoting whether to operate on the dataframe inplace or to return a series contaning the results of the computation. If operating inplace, the derived columns will be named ‘column_join_count’

pvaluestr

a string denoting which pvalue should be returned. Refer to the the Join_Count statistic’s documentation for available p-values

outvalslist of strings

list of arbitrary attributes to return as columns from the Join_Count statistic

**stat_kdict

options to pass to the underlying statistic. For this, see the documentation for the Join_Count statistic.

Returns:
If inplace, None, and operation is conducted on
dataframe in memory. Otherwise, returns a copy of the
dataframe with the relevant columns attached.