相关性计算器

计算两个配对数据集之间的皮尔逊和斯皮尔曼相关系数。含散点图和回归线。

查看指南
配对数据
分别输入X和Y值。两组数量必须相同。用逗号或空格分隔。

快捷预设

指南

What does this tool do

The Correlation Calculator computes the relationship between two paired datasets (X and Y). Enter two lists of numbers with the same length, and it calculates Pearson correlation (linear relationship), Spearman rank correlation (monotonic relationship), and sample covariance. A scatter chart displays your data points plus a linear regression (correlation) line for visual interpretation. Ideal for homework, research, and data analysis when exploring whether two variables are related.

How to use it

  1. Enter X values — Paste or type the first variable (e.g. hours studied). Comma or space separated.
  2. Enter Y values — Paste or type the second variable (e.g. test scores). Must have the same number of values as X.
  3. Calculate — Click the button to compute Pearson r, Spearman ρ, and covariance.
  4. View the chart — The scatter plot shows data points and the regression line.
  5. Try presets — Use Quick Presets for perfect positive, perfect negative, weak positive, or no correlation examples.

How it works

The tool parses both input strings into number arrays (comma or whitespace separated), validates they have the same length (minimum 2, maximum 10,000 pairs), and delegates to the simple-statistics library for:

  • Pearson r — Sample correlation coefficient: covariance(X,Y) / (σ_X × σ_Y). Measures linear association.
  • Spearman ρ — Rank correlation: Pearson applied to rank-transformed data. Measures monotonic association.
  • Covariance — Sample covariance of the two variables.

The scatter chart uses Recharts with lineType="fitting" to draw the linear regression line automatically from your data.

All computation runs entirely in your browser. No data is sent to any server.

Use cases & examples

  • Homework — Compute correlation for paired data in statistics or psychology.
  • Research — Explore relationships between variables (e.g. temperature vs. ice cream sales).
  • Quality — Check if two measurements or processes are related.
  • Finance — Assess correlation between returns of two assets.

Example

Hours studied (X): 2, 4, 6, 8, 10
Test score (Y): 65, 72, 78, 85, 92

  • Pearson r ≈ 0.99 (strong positive)
  • Spearman ρ ≈ 1 (perfect rank correlation)
  • The scatter chart shows points closely following an upward trend line.

Limitations & known constraints

  • Paired data only — X and Y must have exactly the same length.
  • Minimum 2 pairs — At least two (X, Y) pairs are required.
  • Maximum 10,000 pairs — Very long lists may slow the UI.
  • Linear regression — The fitted line assumes a linear relationship; it does not model curves.
  • No significance testing — The tool does not compute p-values; use dedicated software for hypothesis testing.

常见问题

What is Pearson correlation?
Pearson r measures the linear relationship between two variables. It ranges from -1 (perfect negative) to +1 (perfect positive). Zero means no linear correlation.
What is Spearman correlation?
Spearman ρ measures the monotonic relationship (rank-based). It is better than Pearson when data is not normally distributed or has outliers.
How do I interpret the scatter chart?
Points show your (X, Y) pairs. The line is the linear regression (best-fit) line. A steep positive slope indicates positive correlation; steep negative slope indicates negative correlation.

所有计算和转换均完全在您的浏览器中运行。不会向任何服务器发送数据,您的输入不会离开您的设备。