cartodb/agent-skills

carto-spatial-autocorrelation

Builds Moran's I spatial autocorrelation workflows in CARTO.

Ver código-fonte

Como usar

  1. Copie o comando e verifique o pacote antes de instalar no seu ambiente de agente.
  2. Consulte no original as ferramentas, credenciais e ambientes necessários.
  3. Descreva os dados de entrada e a entrega esperada; confira a saída com as fontes.
npx skills add https://github.com/cartodb/agent-skills --skill carto-spatial-autocorrelation

Antes de começar

  • A instalação não inclui assinatura de modelo, franquia API ou acesso aos seus arquivos.
  • Estrelas e instalações indicam atividade, não um teste independente de qualidade ou segurança.
Documento original do Skill

Renderizado do repositório de origem, preservando títulos, exemplos, código, tabelas, links e imagens.

Spatial Autocorrelation with Moran's I

Builds CARTO Workflows that measure spatial autocorrelation using Moran's I, determining whether a variable exhibits clustering, dispersion, or randomness, and classifying each location into HH/HL/LH/LL quadrants.

Prerequisites: Load carto-create-workflow for the development process, JSON structure, and validation commands — it covers both access paths (the MCP server's workflow tools such as create_workflow, validate_workflow, and run_workflow when attached; the carto workflows CLI otherwise; routing signals in carto-basics/references/access-paths.md).

When to use Moran's I vs Getis-Ord Gi*:

  • Moran's I: "Is there clustering?" + classify into cluster types (HH, HL, LH, LL) + identify spatial outliers (HL, LH)
  • Getis-Ord Gi*: "Where are the hotspots/coldspots?" + magnitude of clustering (z-scores)

Instructions

A Moran's I workflow follows this pipeline:

Source Data -> (Filter) -> Spatial Indexing (H3) -> Aggregation -> Moran's I -> (Filter Significant) -> Save

Step 1: Load Source Data

Use native.gettablebyname. The input table typically contains point geometries or pre-indexed grid data.

Success: Node outputs a table with a geometry column (e.g. geom) or an existing spatial index column.

Step 2: Filter (if needed)

Use native.wheresimplified or native.where to narrow the dataset (e.g. filter by category, date range, non-null values).

Success: Output contains only the subset relevant to the analysis.

Step 3: Spatial Indexing

Convert point geometries to H3 cells using native.h3frompoint.

Resolution guidance -- higher resolution = smaller cells = more local patterns:

ResolutionCell sizeUse case
H3 res 7~5 km edgeDistrict/city-level patterns
H3 res 8~2 km edgeNeighborhood-level
H3 res 9~500m edgeStreet-level (used in Berlin POI tutorial)

Success: Every row has a spatial index column (e.g. h3).

Step 4: Aggregate per Cell

Use native.groupby to produce one row per cell with a numeric value:

  • Group by: the spatial index column (h3)
  • Aggregation: geoid,count (or value_col,sum / value_col,avg)

Success: Output has exactly one row per unique cell with a numeric column (e.g. geoid_count).

Step 5: Run Moran's I

Use native.moransi with:

InputDescriptionDefault
indexcolColumn with H3/Quadbin indexesh3
valuecolNumeric column to test for autocorrelationgeoid_count
sizeK-ring neighborhood radius (in hops)3
decayDistance decay function for spatial weightsuniform

Decay options: uniform, inverse, inverse_square, exponential.

  • uniform: Equal weight to all neighbors within the k-ring
  • exponential: Weight decreases exponentially with distance (used in Berlin POI tutorial)

K-ring size: Larger = broader neighborhood = smoother global patterns. Smaller = more localized assessment. The choice of neighborhood size significantly affects results.

Success: Output contains index, morans_i, p_value, and quadrant columns for every cell. (See the Provider casing note in Gotchas — Snowflake surfaces these UPPERCASE.)

Step 6: Filter Significant Results (recommended)

Use native.where to keep only statistically significant cells. Quadrant classification is only meaningful for significant cells.

Common filters:

  • p_value < 0.05 -- all significant cells (95% confidence)
  • p_value < 0.05 AND quadrant = 'HH' -- high-value clusters only
  • p_value < 0.05 AND (quadrant = 'HL' OR quadrant = 'LH') -- spatial outliers only

Success: Only cells with statistically meaningful spatial patterns remain.

Step 7: Save

Use native.saveastable to persist results. The H3/Quadbin column is directly visualizable in CARTO Builder without geometry conversion.

Success: Validated workflow that can be uploaded via create_workflow (MCP) or carto workflows create (CLI).


Output Columns

ColumnMeaning
indexSpatial index cell ID (H3 or Quadbin)
morans_iLocal Moran's I value -- positive = similar neighbors, negative = dissimilar neighbors
p_valueStatistical significance -- lower = more confident
quadrantCluster classification: HH, HL, LH, or LL

Interpreting Results

Global Moran's I (overall pattern):

  • \> 0 = spatial clustering (similar values near each other)
  • < 0 = spatial dispersion (dissimilar values near each other)
  • Near 0 = spatial randomness

Local quadrants (per-cell classification):

QuadrantMeaningInterpretation
HHHigh value surrounded by high valuesCluster core
LLLow value surrounded by low valuesLow-value cluster
HLHigh value surrounded by low valuesSpatial outlier (high anomaly)
LHLow value surrounded by high valuesSpatial outlier (low anomaly)

Gotchas

  • Provider casing & SQL dialect. This skill documents columns in lowercase (BigQuery / Databricks / Postgres / Redshift convention). On Snowflake, unquoted identifiers surface UPPERCASE — reference H3, INDEX, MORANS_I, P_VALUE, QUADRANT, GEOID_COUNT in expressions. See carto-create-workflow/references/providers/<provider>.md for casing rules and SQL dialect equivalents.
  • The Moran's I component requires the Analytics Toolbox. Offline validation can't resolve the AT location — confirm it with a remote verify before running: validate_workflow method: verify over MCP, or carto workflows verify-remote --connection <conn> on the CLI.
  • The output column is named index, not h3 or quadbin. If you need to join back to original data, rename it (e.g. with native.renamecolumn).
  • The valuecol must be numeric. If you are counting features, the group-by step must produce a count column -- do not pass the raw index column as the value.
  • Resolution too high + large area = very many cells, which can be slow or hit memory limits. Start with a moderate resolution and refine.
  • Moran's I is sensitive to the definition of neighborhood. Both k-ring size and decay function choice materially affect results. Document your choices and consider testing alternatives.
  • Quadrant classification is only meaningful for statistically significant cells. Always filter by p_value before interpreting quadrants -- non-significant cells may show any quadrant label by chance.
  • The decay input parameter is named decay (not kernel). Check the component schema if unsure.

Reference Templates

ResourceDescription
BQ TutorialComputing spatial autocorrelation of POI locations in Berlin (BigQuery)
SF TutorialSame tutorial for Snowflake
Workflow template"Computing the spatial auto-correlation of point of interest locations" (available in CARTO Workspace)

Common Variations

VariantHow
Pre-indexed dataSkip Step 3 if data already has H3/Quadbin column
Polygon input instead of pointsUse native.h3polyfill instead of native.h3frompoint
Complete grid (no gaps)Polyfill study area boundary first, then enrich with data (same approach as hotspot analysis)
Combine with Getis-OrdRun both analyses on the same aggregated grid, then join results for a richer picture
Filter to outliers onlyKeep HL and LH quadrants to find anomalous locations

Relacionados por tarefa

do mesmo repositório

Mais Skills

Todos os Skills
cartodb
Comunidade

carto-composite-scoring

Guides the user through building composite score workflows when they ask about composite scores, indexes, multi-variable scores, ranking areas, site scoring, market potential, resilience indexes, risk indexes, weighted scores, PCA, or supervised/unsupervised scoring.

instalações
2
GitHub Stars
6
Atualizado
20 de out.
cartodb
Comunidade

carto-connect-datawarehouse

Choose and configure the data warehouse engine connection for CARTO (BigQuery, Snowflake, Redshift, Postgres, Databricks, Oracle).

instalações
2
GitHub Stars
6
Atualizado
20 de out.
cartodb
Comunidade

carto-create-builder-maps

Author, edit, publish, and validate CARTO Builder maps. Use when the user wants to create a map from a natural-language request, edit an existing map (datasets, layers, styling, privacy, popups, widgets, SQL parameters), duplicate one, upload custom marker icons, or wire up an AI agent on a map. Routes to the CARTO MCP server's map tools (createmap, updatemap, validatemap, readmaps, viewmap) when attached, and to the carto maps CLI — create, update, delete, publish, validate, schema, agents, scr

instalações
2
GitHub Stars
6
Atualizado
20 de out.
cartodb
Comunidade

carto-create-workflow

Builds, schedules, and operates analytics DAGs in CARTO Workflows — the no-code/low-code orchestration layer over the data warehouse. Triggers when the user wants to author a workflow, run/edit one, schedule a DAG, or copy a workflow across profiles or orgs.

instalações
2
GitHub Stars
6
Atualizado
20 de out.