Multiscale Geographically Weighted Regression (MGWR)
Description:
- Functionality to calibrate multiscale (M)GWR as well as traditional GWR. It is built upon the sparse generalized linear modeling (spglm) module.
Resources:
- [GitHub] https://github.com/pysal/mgwr/tree/v2.2.0
- [Examples] https://github.com/pysal/mgwr/tree/v2.2.0/notebooks
Example 1
Section titled “Example 1”Load an example dataset and calibrate the model
import numpy as npimport libpysal as psfrom mgwr.gwr import GWR, MGWRfrom mgwr.sel_bw import Sel_BWimport geopandas as gpimport matplotlib.pyplot as pltimport matplotlib as mplimport pandas as pd
georgia_data = pd.read_csv(ps.examples.get_path('GData_utm.csv'))georgia_shp = gp.read_file(ps.examples.get_path('G_utm.shp'))fig, ax = plt.subplots(figsize=(10,10))georgia_shp.plot(ax=ax, **{'edgecolor':'black', 'facecolor':'white'})georgia_shp.centroid.plot(ax=ax, c='black')
# Prepare Georgia dataset inputsg_y = georgia_data['PctBach'].values.reshape((-1,1))g_X = georgia_data[['PctFB', 'PctBlack', 'PctRural']].valuesu = georgia_data['X']v = georgia_data['Y']g_coords = list(zip(u,v))
g_X = (g_X - g_X.mean(axis=0)) / g_X.std(axis=0)g_y = g_y.reshape((-1,1))g_y = (g_y - g_y.mean(axis=0)) / g_y.std(axis=0)
# Calibrate GWR modelgwr_selector = Sel_BW(g_coords, g_y, g_X)gwr_bw = gwr_selector.search(bw_min=2)print(gwr_bw)gwr_results = GWR(g_coords, g_y, g_X, gwr_bw).fit()
gwr_results.summary()117.0===========================================================================Model type GaussianNumber of observations: 159Number of covariates: 4
Global Regression Results---------------------------------------------------------------------------Residual sum of squares: 71.793Log-likelihood: -162.399AIC: 332.798AICc: 335.191BIC: -713.887R2: 0.548Adj. R2: 0.540
Variable Est. SE t(Est/SE) p-value------------------------------- ---------- ---------- ---------- ----------X0 -0.000 0.054 -0.000 1.000X1 0.458 0.066 6.988 0.000X2 -0.084 0.055 -1.525 0.127X3 -0.374 0.065 -5.734 0.000
Geographically Weighted Regression (GWR) Results---------------------------------------------------------------------------Spatial kernel: Adaptive bisquareBandwidth used: 117.000
Diagnostic information---------------------------------------------------------------------------Residual sum of squares: 51.186Effective number of parameters (trace(S)): 11.805Degree of freedom (n - trace(S)): 147.195Sigma estimate: 0.590Log-likelihood: -135.503AIC: 296.616AICc: 299.051BIC: 335.913R2: 0.678Adjusted R2: 0.652Adj. alpha (95%): 0.017Adj. critical t value (95%): 2.414
Summary Statistics For GWR Parameter Estimates---------------------------------------------------------------------------Variable Mean STD Min Median Max-------------------- ---------- ---------- ---------- ---------- ----------X0 -0.004 0.180 -0.296 0.111 0.208X1 0.477 0.234 0.123 0.556 0.741X2 -0.043 0.083 -0.170 -0.053 0.100X3 -0.328 0.060 -0.464 -0.308 -0.241===========================================================================
ganymede is made by Eugo