esda.Join_Counts_Local_BV

class esda.Join_Counts_Local_BV(connectivity=None, permutations=999, n_jobs=1, keep_simulations=True, seed=None, island_weight=0, drop_islands=True, alternative=None)[source]

Univariate Local Join Count Statistic

Initialize a Local_Join_Counts_BV estimator

Parameters:
connectivity : W | Graph

spatial weights instance as W or Graph aligned with y

permutations : int

number of random permutations for calculation of pseudo p_values

n_jobs : int

Number of cores to be used in the conditional randomisation. If -1, all available cores are used.

keep_simulations : bool (default True)

If True, the entire matrix of replications under the null is stored in memory and accessible; otherwise, replications are not saved

seed : None/int

Seed to ensure reproducibility of conditional randomizations. Must be set here, and not outside of the function, since numba does not correctly interpret external seeds nor numpy.random.RandomState instances.

island_weight=0

value to use as a weight for the “fake” neighbor for every island. If numpy.nan, will propagate to the final local statistic depending on the stat_func. If 0, then the lag is always zero for islands.

drop_islands : bool (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().

alternative : None | str = None

The alternative hypothesis for conditional randomization. See crand.crand() for complete description.

Methods

fit(x, z[, case, n_jobs, permutations])

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_fit_request(*[, case, n_jobs, ...])

Configure whether metadata should be requested to be passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

fit(x, z, case='CLC', n_jobs=1, permutations=999)[source]
Parameters:
x : numpy.ndarray

array containing binary (0/1) data

z : numpy.ndarray

array containing binary (0/1) data

Return type:

the fitted estimator.

Notes

Technical details and derivations can be found in [Anselin and Li, 2019].

Examples

>>> import libpysal
>>> import numpy
>>> w = libpysal.weights.lat2W(4, 4)
>>> x = numpy.ones(16)
>>> x[0:8] = 0
>>> z = [0,1,0,1,1,1,1,1,0,0,1,1,0,0,1,1]
>>> LJC_BV_C1 = Join_Counts_Local_BV(
...     connectivity=w, seed=12345, alternative='two-sided',
... ).fit(x, z, case="BJC")
>>> LJC_BV_C2 = Join_Counts_Local_BV(
...     connectivity=w, seed=12345, alternative='two-sided',
... ).fit(x, z, case="CLC")
>>> LJC_BV_C1.LJC
array([0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0.])
>>> LJC_BV_C1.p_sim
array([  nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan, 1.   ,
       0.234,   nan,   nan,   nan,   nan,   nan,   nan], dtype=float32)
>>> LJC_BV_C2.LJC
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 2., 0., 0., 2., 2.])
>>> LJC_BV_C2.p_sim
array([  nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan, 0.389, 0.509,   nan,   nan, 0.488, 0.65 ], dtype=float32)

Commpop data replicating GeoDa tutorial (Case 1)

>>> import geopandas as gpd
>>> commpop = gpd.read_file(
...     "https://github.com/jeffcsauer/GSOC2020/raw/master/"
...     "validation/data/commpop.gpkg"
... )
>>> w = libpysal.weights.Queen.from_dataframe(commpop, use_index=True)
>>> LJC_BV_Case1 = Join_Counts_Local_BV(
...     connectivity=w, seed=12345, alternative='two-sided',
... ).fit(commpop['popneg'], commpop['popplus'], case='BJC')
>>> LJC_BV_Case1.LJC
array([2., 0., 1., 1., 0., 0., 0., 0., 0., 0., 1., 0., 1., 1., 2., 1., 3.,
       0., 0., 0., 1., 0., 0., 1., 2., 2., 0., 1., 0., 1., 0., 2., 4., 0.,
       0., 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 4., 0., 0., 1., 0., 1., 2., 0., 0., 0., 0., 3., 1., 0., 0., 1.,
       0., 1., 2., 0., 0., 1., 0., 0., 0.])
>>> LJC_BV_Case1.p_sim
array([0.386,   nan, 1.   , 1.   ,   nan,   nan,   nan,   nan,   nan,
         nan, 0.576,   nan, 0.539, 1.   , 0.7  , 1.   , 0.372,   nan,
         nan,   nan, 1.   ,   nan,   nan, 1.   , 0.306, 0.306,   nan,
       1.   ,   nan, 1.   ,   nan, 0.301, 0.12 ,   nan,   nan, 0.368,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan,   nan,   nan,   nan,   nan,   nan,   nan, 0.26 ,   nan,
         nan, 1.   ,   nan, 1.   , 0.694,   nan,   nan,   nan,   nan,
       0.274, 1.   ,   nan,   nan, 1.   ,   nan, 1.   , 0.325,   nan,
         nan, 1.   ,   nan,   nan,   nan], dtype=float32)

Guerry data replicating GeoDa tutorial (Case 2)

>>> import libpysal
>>> import geopandas as gpd
>>> guerry = libpysal.examples.load_example('Guerry')
>>> guerry_ds = gpd.read_file(guerry.get_path('guerry.shp'))
>>> guerry_ds['infq5'] = 0
>>> guerry_ds['donq5'] = 0
>>> guerry_ds.loc[(guerry_ds['Infants'] > 23574), 'infq5'] = 1
>>> guerry_ds.loc[(guerry_ds['Donatns'] > 10973), 'donq5'] = 1
>>> w = libpysal.weights.Queen.from_dataframe(guerry_ds, use_index=True)
>>> LJC_BV_Case2 = Join_Counts_Local_BV(
...     connectivity=w, seed=12345, alternative='two-sided',
... ).fit(guerry_ds['infq5'], guerry_ds['donq5'], case='CLC')
>>> LJC_BV_Case2.LJC
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0.])
>>> LJC_BV_Case2.p_sim
array([  nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan,   nan,   nan,   nan,   nan,   nan, 0.788,   nan,   nan,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan, 1.   ,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan, 0.827,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,   nan,
         nan,   nan, 0.786,   nan,   nan,   nan,   nan,   nan, 0.828,
         nan,   nan,   nan,   nan], dtype=float32)
get_metadata_routing()[source]

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deep : bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_fit_request(*, case='$UNCHANGED$', n_jobs='$UNCHANGED$', permutations='$UNCHANGED$', x='$UNCHANGED$', z='$UNCHANGED$')[source]

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
case : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for case parameter in fit.

n_jobs : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for n_jobs parameter in fit.

permutations : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for permutations parameter in fit.

x : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for x parameter in fit.

z : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for z parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**params : dict

Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance