import { OpenAssistantTool } from '@openassistant/utils'; import { z } from 'zod'; import { GetValues } from '../types'; /** * ## rate Tool * * This tool calculates rates from a base variable and an event variable using various statistical methods. * It's commonly used in epidemiology and spatial analysis to standardize rates across different populations. * * ### Rate Methods * * The rate calculation method can be one of the following types: * - **Raw Rates**: Simple division of events by base population * - **Excess Risk**: Measures excess risk compared to expected values * - **Empirical Bayes**: Uses Bayesian smoothing to stabilize rates * - **Spatial Rates**: Incorporates spatial information in rate calculation * - **Spatial Empirical Bayes**: Combines spatial and Bayesian smoothing * - **EB Rate Standardization**: Empirical Bayes with rate standardization * * ### Parameters * - `datasetName`: Name of the dataset containing the variables * - `baseVariableName`: Name of the base population variable (denominator) * - `eventVariableName`: Name of the event variable (numerator) * - `rateMethod`: Rate calculation method (see above) * - `weightsID`: ID of spatial weights matrix (required for spatial methods) * - `saveData`: Whether to save the calculated rates (optional) * - `outputRateVariableName`: Custom name for the output rate variable (optional) * * **Example user prompts:** * - "Calculate the excess risk rates from the base variable 'population' and the event variable 'crimes'" * - "Compute spatial empirical Bayes rates for disease incidence" * - "Calculate raw crime rates per capita" * * ### Example * ```typescript * import { rate } from "@openassistant/geoda"; * import { convertToVercelAiTool } from "@openassistant/utils"; * * const rateTool = { * ...rate, * context: { * getValues: async (datasetName: string, variableName: string) => { * // Implementation to retrieve values from your data source * return [1000, 2000, 1500, 3000, 2500, 1800, 2200, 1900, 2800, 2100]; * }, * }, * }; * * const result = await generateText({ * model: openai('gpt-4.1', { apiKey: key }), * prompt: 'Calculate the excess risk rates from the base variable "population" and the event variable "crimes"', * tools: { rate: convertToVercelAiTool(rateTool) }, * }); * ``` */ export declare const rate: OpenAssistantTool; export type RateFunctionArgs = z.ZodObject<{ datasetName: z.ZodString; baseVariableName: z.ZodString; eventVariableName: z.ZodString; rateMethod: z.ZodEnum<['Raw Rates', 'Excess Risk', 'Empirical Bayes', 'Spatial Rates', 'Spatial Empirical Bayes', 'EB Rate Standardization']>; weightsID: z.ZodOptional; saveData: z.ZodOptional; outputRateVariableName: z.ZodOptional; }>; export type RateLlmResult = { success: boolean; error?: string; details?: string; result?: string; }; export type RateAdditionalData = { datasetName: string; [key: string]: unknown; }; export type RateContext = { getValues: GetValues; }; export declare function isRateContext(context: unknown): context is RateContext; export type RateTool = typeof rate;