Correlation Analysis
correlationCalculate correlation matrices between multiple variables using Pearson's r or Spearman's rank. Choose matrix or pairwise output to analyze linear or monotonic relationships.
Instructions
Calculate correlation matrices between multiple variables using Polars.
Methods: - pearson: Linear correlation (-1 to +1, 0 = no linear relationship) - spearman: Rank-based correlation (monotonic, robust to outliers)
Examples:
PEARSON CORRELATION: data={"x":[1,2,3], "y":[2,4,6], "z":[1,1,1]}, method="pearson", output_format="matrix" Result: { "x": {"x":1.0, "y":1.0, "z":NaN}, "y": {"x":1.0, "y":1.0, "z":NaN}, "z": {"x":NaN, "y":NaN, "z":NaN} }
PAIRWISE FORMAT: data={"height":[170,175,168], "weight":[65,78,62]}, method="pearson", output_format="pairs" Result: [{"var1":"height", "var2":"weight", "correlation":0.89}]
SPEARMAN (RANK): data={"x":[1,2,100], "y":[2,4,200]}, method="spearman" Result: Perfect correlation (1.0) despite non-linear relationship
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification. | |
| output_mode | No | Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details. | full |
| data | Yes | Dict of variable names to values (e.g., {'x':[1,2,3],'y':[2,4,6]}) | |
| method | No | Correlation method | pearson |
| output_format | No | Output format: 'matrix' or 'pairs' | matrix |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |