From 5c0d857cfd20e0d298535a8e435ef7166757d371 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 31 Jul 2024 10:11:56 +0200 Subject: [PATCH] remove splot completely --- autocorrelation/exercise_answers.qmd | 14 ++++++-------- autocorrelation/hands_on.qmd | 9 +++++++-- environment.yml | 1 - regression/hands_on.qmd | 12 +++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/autocorrelation/exercise_answers.qmd b/autocorrelation/exercise_answers.qmd index 0b1dac43..e96e1ae8 100644 --- a/autocorrelation/exercise_answers.qmd +++ b/autocorrelation/exercise_answers.qmd @@ -62,7 +62,7 @@ Measure Join Counts statistic on your new variable. ```py jc = esda.Join_Counts( glasgow["better_half"], - contiguity.to_W(), + contiguity, ) ``` @@ -110,7 +110,7 @@ ax.axhline(0, c="black", alpha=0.5) Calculate Moran's $I$ ```py -mi = esda.Moran(glasgow['rank_std'], contiguity_r.to_W()) +mi = esda.Moran(glasgow['rank_std'], contiguity_r) ``` ```py @@ -124,27 +124,25 @@ mi.p_sim Calculate LISA statistics for the areas ```py -lisa = esda.Moran_Local(glasgow['rank_std'], contiguity_r.to_W()) +lisa = esda.Moran_Local(glasgow['rank_std'], contiguity_r) ``` Make a map of significant clusters at the 5% ```py -from splot.esda import lisa_cluster - -_ = lisa_cluster(lisa, glasgow) +lisa.explore(glasgow) ``` Create cluster maps for significance levels 1% ```py -_ = lisa_cluster(lisa, glasgow, p=.01) +lisa.explore(glasgow, crit_value=.01) ``` Create cluster maps for significance levels 10%; ```py -_ = lisa_cluster(lisa, glasgow, p=.1) +lisa.explore(glasgow, crit_value=.1) ``` Can you create both interactive and static versions of those maps? diff --git a/autocorrelation/hands_on.qmd b/autocorrelation/hands_on.qmd index bfefb049..257dea68 100644 --- a/autocorrelation/hands_on.qmd +++ b/autocorrelation/hands_on.qmd @@ -530,10 +530,15 @@ global Moran's $I$, you select 5% as the threshold for statistical significance. You can quickly map these results using the `explore()` method. ```{python} -lisa.explore(elections, crit_value=0.05) # <1> +lisa.explore( + elections, # <1> + crit_value=0.05, # <2> + prefer_canvas=True, + tiles="CartoDB Positron", +) ``` 1. `lisa` does not save geometry so you need to pass the original GeoDataFrame as a source of geometric information. - +2. You can specify a custom threshold of significance. ::: {.callout-tip collapse="true"} # Plotting LISA manually diff --git a/environment.yml b/environment.yml index 9d6e3d12..41c23664 100644 --- a/environment.yml +++ b/environment.yml @@ -26,7 +26,6 @@ dependencies: - rasterio >=1.3 - scikit-learn - seaborn >=0.13 - - splot >=1.1 - spglm >=1.1 - spreg >=1.4 - statsmodels >=0.14 diff --git a/regression/hands_on.qmd b/regression/hands_on.qmd index ea008e3c..73c46b2a 100644 --- a/regression/hands_on.qmd +++ b/regression/hands_on.qmd @@ -26,7 +26,6 @@ import pandas as pd import seaborn as sns import statsmodels.formula.api as sm from libpysal import graph -from splot.esda import lisa_cluster ``` ## Data @@ -222,18 +221,17 @@ plt.axhline(0, c="black", alpha=0.5); That looks like a pretty strong relationship. Use the local version of Moran's statistic to find out the clusters. ```{python} -lisa = esda.Moran_Local(elections_data['residual'], contiguity_r.to_W()) # <1> +lisa = esda.Moran_Local(elections_data['residual'], contiguity_r) # <1> ``` -1. Use `Moran_Local` function from `esda` and remember that it needs `W`, not `Graph`. +1. Use `Moran_Local` function from `esda`. -Let's use our handy `lisa_cluster` function from `splot` to visualise the results. +Let's visualise the results. ```{python} #| fig-cap: LISA clusters -_ = lisa_cluster(lisa, elections_data) +lisa.explore(elections_data, prefer_canvas=True, tiles="CartoDB Positron") ``` - -The outcome of LISA shows large clusters of both overpredicted (high-high) and underpredicted (low-low) areas. The underpredicted are mostly in central Bohemia around Prague and in the mountains near the borders, where the ski resorts are. Putting aside the central areas for a bit, the explanation of underprediction in mountains is relatively straightforward. The education data are linked to the residents of each municipality. The people who voted in a municipality do not necessarily need to match with residents. It is known that more affluent population groups, who are more likely to go to a ski resort, voted overwhelmingly for Pavel. And since the elections were in winter, a lot of them likely voted in ski resorts, affecting the outcome of the model. +The outcome of LISA shows large clusters of both overpredicted (High-High) and underpredicted (Low-Low) areas. The underpredicted are mostly in central Bohemia around Prague and in the mountains near the borders, where the ski resorts are. Putting aside the central areas for a bit, the explanation of underprediction in mountains is relatively straightforward. The education data are linked to the residents of each municipality. The people who voted in a municipality do not necessarily need to match with residents. It is known that more affluent population groups, who are more likely to go to a ski resort, voted overwhelmingly for Pavel. And since the elections were in winter, a lot of them likely voted in ski resorts, affecting the outcome of the model. The overpredicted areas, on the other hand, are known for higher levels of deprivation, which may have played a role in the results. What is clear, is that geography plays a huge role in the modelling of the elections.