Skip to main content

A simple Python package for the geodetector

Project description

py-geodetector

A simple and efficient Python package for the Geographical Detector (GeoDetector).

Features

  • Four Detectors: Factor, Interaction, Risk, and Ecological detectors.
  • High Performance: Vectorized calculations using Pandas and NumPy for large-scale datasets.
  • Flexible API: Supports both batch processing and interactive exploratory analysis.
  • Auto Detection: Automatically identifies discrete/categorical variables as factors.
  • Visualization: Built-in heatmap for interaction results with statistical significance markers.

Install

pip install py-geodetector

Usage

1. Data Preparation

  • Format: pandas DataFrame.
  • Y (Dependent Variable): Numerical/Continuous.
  • X (Independent Variable): Categorical/Discrete. If your $X$ is continuous, you must discretize it first (e.g., using pd.qcut or Jenks natural breaks).

2. Quick Start

from geodetector import load_example_data, GeoDetector

# Load example disease dataset
df = load_example_data()

# Initialize: Automatically detects discrete columns as factors if 'factors' is not provided
gd = GeoDetector(df, y='incidence')
print(f"Detected factors: {gd.factors}")

# 1. Factor Detector
# Batch detection for all factors
factor_df = gd.factor_detector()
# Single factor detection: returns (q_value, p_value)
q, p = gd.factor_detector('type')

# 2. Interaction Detector
# Full matrix calculation
interaction_df = gd.interaction_detector()
# Pairwise detection with relationship description
q_inter, relationship = gd.interaction_detector('type', 'region', relationship=True)

# 3. Ecological Detector
# Determine if the impact of two factors are significantly different
eco_df = gd.ecological_detector()

# 4. Risk Detector
# Compare average Y between sub-groups of a factor
risk_result = gd.risk_detector('type')
print(risk_result['risk']) # Mean values for each stratum

# 5. Visualization
# Plot interaction heatmap (red markers indicate significant ecological difference)
gd.plot(factors=['type', 'region', 'level'])

3. Visualization Result

The plot() method generates a heatmap of the interaction $q$-statistics. Red text indicates that the ecological detector shows a significant difference ($p < 0.05$) between those factors.

References

@article{wang2010geographical,
  title={Geographical detectors-based health risk assessment and its application in the neural tube defects study of the Heshun Region, China},
  author={Wang, Jin-Feng and Li, Xin-Hu and Christakos, George and Liao, Yi-Lan and Zhang, Tin and Gu, Xue and Zheng, Xiao-Ying},
  journal={International Journal of Geographical Information Science},
  volume={24},
  number={1},
  pages={107-127},
  year={2010},
  publisher={Taylor \& Francis}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_geodetector-0.2.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_geodetector-0.2.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file py_geodetector-0.2.1.tar.gz.

File metadata

  • Download URL: py_geodetector-0.2.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for py_geodetector-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1fa5f00fdc29ba31a50413a9949ff9f393f23563e0a30e83a78cb5c88d5a7f08
MD5 865bfd72234b9504352b461d32488f18
BLAKE2b-256 137a679172849602a63313c6047771d51b18b3d4bd694360f0f49a921207dc8a

See more details on using hashes here.

File details

Details for the file py_geodetector-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: py_geodetector-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for py_geodetector-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8398417cab723c0608d43b9a4a1585f544a7c73566b0228d9298bfe1418836a
MD5 3aad140180bbc324265c013f27bfd5d6
BLAKE2b-256 58a07147f5886022449c1abd4b239a3e310f916d3f81e0028544e5cf01ba2f16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page