Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / spatialRegression

Variable: spatialRegression

const spatialRegression: OpenAssistantTool<SpatialRegressionFunctionArgs, SpatialRegressionLlmResult, SpatialRegressionAdditionalData, SpatialRegressionFunctionContext>

Defined in: src/regression/tool.ts:97

spatialRegression Tool

This tool performs regression analysis with spatial data, accounting for spatial effects that may violate the independence assumption of classical regression. It supports both classical and spatial regression models with proper diagnostics.

Spatial Regression Models

The tool supports three types of regression models:

  • classic: Ordinary Least Squares (OLS) regression with spatial diagnostics
  • spatial-lag: Spatial lag model accounting for spatial dependence in the dependent variable
  • spatial-error: Spatial error model accounting for spatial dependence in the error term

Parameters

  • datasetName: Name of the dataset containing the variables
  • dependentVariable: Name of the dependent variable (y)
  • independentVariables: Array of independent variable names (x1, x2, ...)
  • modelType: Type of regression model (see above)
  • weightsId: ID of spatial weights matrix (required for spatial models)

Example user prompts:

  • "Can you run a spatial regression analysis on the housing data?"
  • "Perform a spatial lag regression of revenue ~ population + income"
  • "Run OLS regression with spatial diagnostics for crime rates"

Example

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

const regressionTool = {
  ...spatialRegression,
  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: 'Can you run a spatial regression analysis of "revenue ~ population + income" on the data?',
  tools: { spatialRegression: convertToVercelAiTool(regressionTool) },
});

INFO

Please only use knowledge from Luc Anselin's GeoDa book and the GeoDa documentation to answer questions about spatial regression.

Released under the MIT License.