Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / rate

Variable: rate ​

const rate: OpenAssistantTool<RateFunctionArgs, RateLlmResult, RateAdditionalData, RateContext>

Defined in: src/rate/tool.ts:67

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) },
});

Released under the MIT License.