esda.LOSH

class esda.LOSH(connectivity=None, inference=None)[source]

Local spatial heteroscedasticity (LOSH)

Initialize a losh estimator

Parameters:
connectivity : W | Graph

spatial weights instance as W or Graph aligned with y

inference : str

describes type of inference to be used. options are “chi-square” or “permutation” methods.

Hi[source]

Array of LOSH values for each spatial unit.

Type:

numpy array

ylag[source]

Spatially lagged y values.

Type:

numpy array

yresid[source]

Spatially lagged residual values.

Type:

numpy array

VarHi[source]

Variance of Hi.

Type:

numpy array

pval[source]

P-values for inference based on either “chi-square” or “permutation” methods.

Type:

numpy array

Methods

fit(y[, a])

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_fit_request(*[, a])

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

set_params(**params)

Set the parameters of this estimator.

fit(y, a=2)[source]
Parameters:
y : numpy.ndarray

array containing continuous data

a : int

residual multiplier. Default is 2 in order to generate a variance measure. Users may use 1 for absolute deviations.

Return type:

the fitted estimator.

Notes

Technical details and derivations can be found in [Ord and Getis, 2012].

Examples

>>> import libpysal, numpy
>>> w = libpysal.io.open(libpysal.examples.get_path("stl.gal")).read()
>>> f = libpysal.io.open(libpysal.examples.get_path("stl_hom.txt"))
>>> y = numpy.array(f.by_col['HR8893'])
>>> from esda import LOSH
>>> ls = LOSH(connectivity=w, inference="chi-square").fit(y)
>>> numpy.round(ls.Hi[0], 3)
np.float64(0.776)
>>> numpy.round(ls.pval[0], 3)
np.float64(0.228)

Boston housing data replicating R spdep::LOSH()

>>> import geopandas as gpd
>>> boston = libpysal.examples.load_example('Bostonhsg')
>>> boston_ds = gpd.read_file(boston.get_path('boston.shp'))
>>> w = libpysal.weights.Queen.from_dataframe(boston_ds, use_index=False)
>>> ls = LOSH(connectivity=w, inference="chi-square").fit(boston_ds['NOX'])
>>> numpy.round(ls.Hi[0], 3)
np.float64(0.197)
>>> numpy.round(ls.VarHi[0], 3)
np.float64(0.814)
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(*, a='$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:
a : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for a 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