esda.Moran_BV_matrix

esda.Moran_BV_matrix(variables, w, permutations=0, varnames=None)[source]

Bivariate Moran Matrix

Calculates bivariate Moran between all pairs of a set of variables.

Parameters:
variables : array or pandas.DataFrame

sequence of variables to be assessed

w : W | Graph

spatial weights instance as W or Graph aligned with variables

permutations : int

number of permutations

varnames : list, optional if variables is an array

Strings for variable names. Will add an attribute to Moran_BV objects in results needed for plotting in splot or .plot(). Default =None. Note: If variables is a pandas.DataFrame varnames will automatically be generated

Returns:

results – (i, j) is the key for the pair of variables, values are the Moran_BV objects.

Return type:

dictionary

Examples

open dbf

>>> import libpysal
>>> f = libpysal.io.open(libpysal.examples.get_path("sids2.dbf"))

pull of selected variables from dbf and create numpy arrays for each

>>> varnames = ['SIDR74',  'SIDR79',  'NWR74',  'NWR79']
>>> vars = [np.array(f.by_col[var]) for var in varnames]

create a contiguity matrix from an external gal file

>>> w = libpysal.io.open(libpysal.examples.get_path("sids2.gal")).read()

create an instance of Moran_BV_matrix

>>> from esda import Moran_BV_matrix
>>> res = Moran_BV_matrix(vars, w, varnames=varnames)

check values

>>> round(res[(0, 1)].I, 7)
np.float64(0.1936261)
>>> round(res[(3, 0)].I, 7)
np.float64(0.3770138)