Correlation measures how strongly two numeric variables move together, on a scale from −1 to +1. Pearson's r captures straight-line relationships; Spearman's ρ captures any monotonic trend and resists outliers. r = 0 means no linear relationship, ±1 means a perfect one. Crucially, correlation is not causation, and r only detects linear patterns and is easily distorted by outliers. The p-value tells you whether r differs from zero. Results here are validated against SciPy to full precision.

When to use correlation

Use correlation to quantify the strength and direction of association between two continuous variables — study hours and exam score, temperature and sales. Choose Pearson's r when the relationship is roughly linear and the data has no extreme outliers; choose Spearman's ρ for ranked/ordinal data or when outliers or curvature are present.

If you want to predict one variable from another rather than just measure association, use linear regression instead.

Interpreting the magnitude

A common rule of thumb (Cohen): |r| ≈ 0.1 is small, 0.3 moderate, and 0.5 or above large — but context matters enormously across fields. The square of r (r²) is the share of variance the linear relationship explains: r = 0.5 explains just 25%.

Assumptions and cautions

Common mistakes

Worked example

Hours studied 1,2,3,4,5 against scores 52,58,63,71,78 gives r ≈ 0.997 — a very strong positive linear relationship, with a p-value well below 0.05. Paste two equal-length columns above to compute r, the p-value, and r². Computation details are on the methodology page.

Guide: Correlation

Correlation measures the strength and direction of the linear relationship between two continuous variables. It ranges from −1 (perfect negative) to +1 (perfect positive), with 0 indicating no linear relationship.

Example: height and weight have a strong positive correlation (~0.7). As one tends to increase, so does the other.

Pearson r measures linear correlation and assumes both variables are continuous and approximately normally distributed. It is the default choice.

Spearman ρ is rank-based — it measures monotonic (not necessarily linear) correlation. Use Spearman when:

  • Data is ordinal (e.g. ratings, rankings)
  • The relationship is non-linear but monotonic
  • There are significant outliers
  • Normality cannot be assumed

Two variables can be strongly correlated without one causing the other. Possible reasons for a spurious correlation include:

  • Confounding variable: A third variable causes both (e.g. ice cream sales and drowning rates are both caused by hot weather)
  • Coincidence: Two unrelated time series that happen to trend together
  • Reverse causation: Y causes X, not X causes Y

Establishing causation requires randomised experiments, not just correlation.

r² (the coefficient of determination) tells you the proportion of variance in Y that is explained by its linear relationship with X. An r² of 0.64 means that 64% of the variability in Y can be explained by X.

For example, if height and weight have r = 0.8, then r² = 0.64 — height explains 64% of the variation in weight. The remaining 36% is due to other factors.