import { OpenAssistantTool } from '@openassistant/utils'; import { z } from 'zod'; import { LinearRegressionResult, SpatialErrorResult, SpatialLagResult } from '@geoda/regression'; import { GetValues } from '../types'; export type SpatialRegressionFunctionArgs = z.ZodObject<{ datasetName: z.ZodString; dependentVariable: z.ZodString; independentVariables: z.ZodArray; modelType: z.ZodEnum<['classic', 'spatial-lag', 'spatial-error']>; weightsId: z.ZodOptional; }>; export type SpatialRegressionLlmResult = { success: boolean; result?: string; error?: string; }; export type SpatialRegressionAdditionalData = { datasetName: string; report: LinearRegressionResult | SpatialLagResult | SpatialErrorResult | null; }; export type SpatialRegressionFunctionContext = { getValues: GetValues; config?: { theme?: string; }; }; /** * ## 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) }, * }); * ``` * * :::note * Please only use knowledge from Luc Anselin's GeoDa book and the GeoDa documentation to answer questions about spatial regression. * ::: */ export declare const spatialRegression: OpenAssistantTool; export type SpatialRegressionTool = typeof spatialRegression; type SpatialRegressionArgs = { datasetName: string; dependentVariable: string; independentVariables: string[]; modelType: string; weightsId?: string; }; export declare function isSpatialRegressionArgs(args: unknown): args is SpatialRegressionArgs; export {};