Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / globalMoran

Variable: globalMoran

const globalMoran: OpenAssistantTool<MoranScatterPlotFunctionArgs, MoranScatterPlotLlmResult, MoranScatterPlotAdditionalData, MoranScatterPlotFunctionContext>

Defined in: src/global-moran/tool.ts:99

globalMoran Tool

This tool calculates Global Moran's I for a given variable to test for spatial autocorrelation. It measures whether similar values tend to cluster together in space or are randomly distributed.

Global Moran's I

Global Moran's I is a measure of spatial autocorrelation that ranges from -1 to +1:

  • Positive values: Indicate positive spatial autocorrelation (clustering of similar values)
  • Negative values: Indicate negative spatial autocorrelation (dispersion of similar values)
  • Values near 0: Indicate no spatial autocorrelation (random distribution)

Parameters

  • datasetName: Name of the dataset containing the variable
  • variableName: Name of the numerical variable to analyze
  • weightsId: ID of spatial weights matrix (optional, will use cached weights if available)

Example user prompts:

  • "Is the population data spatially clustered or dispersed?"
  • "Calculate Global Moran's I for the income variable"
  • "Test for spatial autocorrelation in housing prices"

Example

typescript
import { globalMoran } from "@openassistant/geoda";
import { convertToVercelAiTool } from "@openassistant/utils";

const moranTool = {
  ...globalMoran,
  context: {
    getValues: async (datasetName: string, variableName: string) => {
      // Implementation to retrieve values from your data source
      return [100, 200, 150, 300, 250, 180, 220, 190, 280, 210];
    },
  },
};

const result = await generateText({
  model: openai('gpt-4.1', { apiKey: key }),
  prompt: 'Calculate Global Moran\'s I for the population data',
  tools: { globalMoran: convertToVercelAiTool(moranTool) },
});

INFO

The global Moran's I tool should always be used with the spatialWeights tool. The LLM models know how to use the spatialWeights tool for the Moran scatterplot analysis.

Released under the MIT License.