%matplotlib inline
import geopandas
import numpy
import pandas
import matplotlib.pyplot as plt
from pysal.lib import weights
from pysal.explore import esda
from pysal.viz.splot import esda as esdaplot
db = geopandas.read_file("../data/lux_regions.gpkg")
w = weights.Queen.from_dataframe(db)
w.transform = "R"
ll_lag = weights.lag_spatial(w, db["light_level"])
pandas.Series(ll_lag).head()
0 1639.250000 1 1016.857143 2 1386.000000 3 2495.000000 4 866.750000 dtype: float64
mi = esda.Moran(db["light_level"], w)
esdaplot.moran_scatterplot(mi);
esdaplot.plot_moran_simulation(mi, aspect_equal=False);
lisa = esda.Moran_Local(db["light_level"], w)
esdaplot.lisa_cluster(lisa, db);
esdaplot.plot_local_autocorrelation(lisa, db, "light_level");
pandas.Series(lisa.p_sim).head()
0 0.061 1 0.458 2 0.143 3 0.014 4 0.215 dtype: float64
f, axs = plt.subplots(1, 3, figsize=(16, 3))
for i, ax in zip([0.05, 0.01, 0.001], axs):
esdaplot.lisa_cluster(lisa, db, p=i, ax=ax)
ax.set_title(f"Confidence threshold = {i}")
light_level
and its spatial lag. How do they relate to each other? What can you say about the lag in comparison to the original variable?POPULATION
. What are the main similarities and differences?