Geographically Weighted Summary Statistics (GWAverage / GWCorrelation)

Model Overview

Geographically Weighted Summary Statistics performs locally weighted descriptive statistics on multivariate data, revealing spatial heterogeneity in the statistical characteristics of variables.

Two classes are provided:

  • GWAverage — computes local mean, standard deviation, variance, skewness, coefficient of variation, and optionally local median, interquartile range, and quantile imbalance.

  • GWCorrelation — computes local Pearson correlation coefficients and Spearman rank correlation coefficients for every pair of variables.

GWAverage

For each variable, the following local statistics are computed:

Statistic

Attribute

Column Name

Local Mean

local_mean

{variable}_Mean

Local Std Dev

local_sdev

{variable}_SDev

Local Skewness

local_skewness

{variable}_Skew

Local CV

local_cv

{variable}_CV

When quantile=True:

Statistic

Attribute

Column Name

Local Median

local_median

{variable}_Median

IQR

iqr

{variable}_IQR

Quantile Imbalance

qi

{variable}_QI

GWCorrelation

For each pair of variables \((X_i, X_j)\), the following are computed:

  • Local Pearson correlation coefficient — via locally weighted covariance

  • Local Spearman rank correlation coefficient — via locally weighted correlation on ranked data

Column name format: {var1}.{var2}_Corr and {var1}.{var2}_SCorr.

Code Examples

GWAverage

from pygwmodel import GWAverage, BandwidthWeight

vars = ["PURCHASE", "FLOORSZ", "UNEMPLOY", "PROF"]

gwa = GWAverage(
    data, vars,
    weight=BandwidthWeight(36.0, adaptive=True),
    quantile=False
).run()

result = gwa.result_layer
print(result.columns)
# PURCHASE_Mean, PURCHASE_SDev, PURCHASE_Skew, PURCHASE_CV,
# FLOORSZ_Mean, ...

GWCorrelation

from pygwmodel import GWCorrelation, BandwidthWeight

gwc = GWCorrelation(data, vars, weight=BandwidthWeight(36.0, adaptive=True))
result = gwc.run().result_layer

print(result.columns)
# PURCHASE.FLOORSZ_Corr, PURCHASE.FLOORSZ_SCorr,
# PURCHASE.UNEMPLOY_Corr, ...

Parallel Execution

Both classes support OpenMP multi-threading:

from pygwmodel import GWAverage, GWCorrelation, ParallelType

gwa = GWAverage(data, vars, weight=...)
gwa.enable_parallel(ParallelType.OpenMP, threads=4).run()

gwc = GWCorrelation(data, vars, weight=...)
gwc.enable_parallel(ParallelType.OpenMP, threads=4).run()