Correlation coefficient: Pearson r, p-value and interval
The correlation coefficient measures how strongly two variables move together in a straight line. Pearson's r runs from −1 (a perfect falling line) through 0 (no linear relation) to +1 (a perfect rising line). A test of r against 0 tells you whether the relation could be chance, and a confidence interval tells you how strong it plausibly is. Spearman's rho does the same job on ranks, for relations that are monotonic but not straight.
When to use it
- You want to know whether a process input (temperature, pressure, speed) is related to an output (strength, dimension, yield).
- You are screening many variables for the ones worth studying further, often with a matrix plot.
- You want to check whether two measurements of the same thing agree in their ranking of parts.
- When you need to predict one variable from the other or set a tolerance on the input, go on to regression or a fitted line plot.
How it works
For n pairs (xᵢ, yᵢ), Pearson's correlation is the covariance divided by the product of the two standard deviations:
r = Σ (xᵢ − x̄)(yᵢ − ȳ) / √( Σ (xᵢ − x̄)² · Σ (yᵢ − ȳ)² )Test. H₀: ρ = 0 (no linear relation in the process) against H₁: ρ ≠ 0. If the pairs come from a bivariate normal distribution, this statistic has a t distribution under H₀:
t = r √(n − 2) / √(1 − r²), df = n − 2Confidence interval (Fisher's z transformation): z = artanh(r) is close to normal with standard error 1/√(n − 3). Build the interval on the z scale and transform back with tanh:
tanh( artanh(r) ± z(1 − α/2) / √(n − 3) )r² is the fraction of the variation in y that a straight line on x accounts for.
Spearman's rho is Pearson's r computed on the ranks of x and of y (tied values share the average rank). It measures any monotonic relation, rising or falling, and resists outliers.
Assumptions: independent pairs; for the p-value and interval, roughly bivariate normal data. Pearson's r itself only measures straight-line association.
Try it: change the correlation and see how tightly the points follow the line.
- r
- 0.80
- R²
- 0.64
- Least-squares line
- Y = −3.00 + 0.250 X
r = 0.80: as X increases, Y tends to increase. R² = 0.64, so the least-squares line explains 64% of the variation in Y.
Example
A packaging line seals pouches with heated jaws. The engineer suspects that the jaw temperature drifts during a shift and affects seal strength. She records the jaw temperature and pulls one pouch at each of 15 points in the shift, measuring seal strength in N per 15 mm:
| Jaw temp (°C) | 150 | 140 | 154 | 162 | 142 | 168 | 156 | 158 | 154 | 169 | 163 | 156 | 169 | 169 | 148 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Strength (N/15 mm) | 2.25 | 2.48 | 2.77 | 2.49 | 1.64 | 2.88 | 2.70 | 2.65 | 2.32 | 3.08 | 2.93 | 2.46 | 2.75 | 3.05 | 2.38 |
Results:
- r = 0.787, so r² = 0.620.
- t = 0.787 × √13 / √(1 − 0.620) = 4.60 with 13 degrees of freedom; p = 0.0005.
- Fisher z: artanh(0.787) = 1.064, standard error 1/√12 = 0.289, so the 95% interval is tanh(1.064 ± 1.960 × 0.289) = 0.46 to 0.93.
- Spearman's rho = 0.81.
- The least-squares line has a slope of 0.030 N/15 mm per °C.
How to read the results
- The relation is real. With p = 0.0005, a correlation this strong would be very unlikely if temperature and strength were unrelated.
- It is strong but not exact. r² = 0.62 means temperature accounts for about 62% of the variation in seal strength in this sample; the rest comes from other sources (film thickness, dwell time, pressure, the test itself).
- The interval is wide. With only 15 pairs, the true correlation could be as low as 0.46. Do not quote r = 0.79 as if it were exact.
- In process terms, every 10 °C drop in jaw temperature costs about 0.3 N/15 mm of seal strength. If the lower specification is 2.0 N/15 mm, the coolest seals (around 140 °C) are at risk. The next step is to control the jaw temperature, and possibly to set its operating window from the required strength with a realistic tolerance parallelogram or regression.
- Spearman agrees (0.81), so the result does not hinge on one or two unusual points.
Common mistakes
- Reading correlation as cause. Here the physics supports a causal link, but in observational data both variables may follow a third one, such as time of day.
- Skipping the plot. A single outlier can create or destroy a correlation, and a strong curved relation can have r near 0. Always look at a scatterplot.
- Using r to compare measurement methods. Two gauges can correlate at 0.99 and still differ by a constant offset. Use a paired t-test or a bias study.
- Restricting the range. If temperature had only been sampled between 155 and 160 °C, the correlation would look weak even though the effect is the same.
Frequently asked questions
What is a strong correlation?
It depends on the purpose. For a physical process input and output, |r| above about 0.8 usually means the input is a dominant cause; 0.3 to 0.6 means it matters but other sources do too. Always pair r with its confidence interval and the plot.
What is the difference between Pearson and Spearman correlation?
Pearson measures straight-line association on the original values. Spearman measures monotonic association on ranks, so it handles curved but steadily rising or falling relations and is less affected by outliers.
Is a significant correlation an important one?
Not necessarily. With hundreds of pairs, r = 0.1 can be significant while explaining only 1% of the variation. Look at r² and the slope in engineering units.
What is the difference between correlation and regression?
Correlation measures the strength of a linear relation and treats both variables alike. Regression fits an equation to predict one variable from the other and gives the slope, prediction intervals and residuals.