Correlation Coefficient Calculator with Regression Equation
A correlation coefficient calculator with regression equation: paste paired X and Y values to get Pearson's r, r², the best-fit line and a p-value.
Pearson correlation (r)
- r² (coefficient of determination)
- 0.9885
- Number of pairs (n)
- 6
- Mean of X
- 6
- Mean of Y
- 71.6667
- Slope (b)
- 4.4286
- Intercept (a)
- 45.0952
- t statistic (df = 4)
- 18.5077
- p-value (two-tailed)
- < 0.0001
Regression line: ŷ = 45.0952 + 4.4286x
How to use the Correlation Coefficient Calculator
- Type or paste the X values into the first box, separated by commas, spaces or new lines.
- Paste the matching Y values into the second box in the same order, so the 1st X pairs with the 1st Y.
- Read Pearson's r and its strength label, then r², the means and the regression line below it.
- Use the t statistic and two-tailed p-value to judge whether the correlation could be due to chance.
Formula
r = Sxy ÷ √(Sxx × Syy) ŷ = a + bx, b = Sxy ÷ Sxx t = r√(n − 2) ÷ √(1 − r²)
Where:
- n
- The number of (x, y) pairs
- x̄, ȳ
- The mean of the X values and the mean of the Y values
- Sxx
- Σ(x − x̄)², the sum of squared deviations of X from its mean
- Syy
- Σ(y − ȳ)², the sum of squared deviations of Y from its mean
- Sxy
- Σ(x − x̄)(y − ȳ), the sum of the products of the paired deviations
- r
- Pearson's correlation coefficient, from −1 (perfect negative) to +1 (perfect positive)
- r²
- The share of the variation in Y explained by the straight-line fit
- b, a
- Slope and intercept of the least-squares line; a = ȳ − b·x̄
- t
- Test statistic for “no correlation” (ρ = 0), with n − 2 degrees of freedom
Pearson's r measures linear association only. The p-value assumes the pairs are independent and roughly bivariate normal. Strength labels use the common rule of thumb |r| < 0.2 very weak, 0.2–0.39 weak, 0.4–0.59 moderate, 0.6–0.79 strong, 0.8+ very strong.
Worked example
A small shop records monthly ad spend (X) of $1,200, $1,500, $1,800, $2,100, $2,500 and $3,000, and sales (Y) of $14,200, $15,800, $17,100, $19,500, $21,000 and $24,300. How closely do sales track ad spend?
- Means: x̄ = 12,100 ÷ 6 = $2,016.67 and ȳ = 111,900 ÷ 6 = $18,650.
- Sums of squared deviations: Sxx = 2,188,333.33, Syy = 68,495,000 and Sxy = 12,205,000.
- r = 12,205,000 ÷ √(2,188,333.33 × 68,495,000) = 12,205,000 ÷ 12,242,952.73 = 0.9969.
- r² = 0.9969² = 0.9938, so about 99.4% of the month-to-month variation in sales lines up with ad spend.
- Slope b = 12,205,000 ÷ 2,188,333.33 = 5.5773 and intercept a = 18,650 − 5.5773 × 2,016.67 = 7,402.44.
- t = r × √(6 − 2) ÷ √(1 − r²) = 25.34 with unrounded r, on 4 degrees of freedom, so p < 0.0001.
r = 0.9969, a very strong positive correlation. The fitted line is sales ≈ $7,402.44 + 5.5773 × ad spend, and the p-value is below 0.0001.
How to calculate the correlation coefficient (Pearson's r)
Pearson's r is a single number between −1 and +1 that says how closely paired values follow a straight line. Near +1, high X comes with high Y; near −1, Y falls as X rises; near 0, there is no straight-line pattern. It has no units, so switching Celsius to Fahrenheit or dollars to cents leaves it unchanged.
A beach kiosk notes the afternoon temperature and the ice creams sold on seven days:
| Temperature (°C) | Ice creams sold |
|---|---|
| 14 | 215 |
| 16 | 325 |
| 20 | 332 |
| 23 | 406 |
| 26 | 412 |
| 29 | 522 |
| 31 | 614 |
- The means are x̄ = 159 ÷ 7 ≈ 22.71 °C and ȳ = 2,826 ÷ 7 ≈ 403.71 ice creams.
- Subtracting the means and summing gives Sxx ≈ 247.43, Syy ≈ 105,237.43 and Sxy ≈ 4,881.43.
- r = 4,881.43 ÷ √(247.43 × 105,237.43) ≈ 0.9566, a very strong positive correlation.
- With 5 degrees of freedom, t ≈ 7.34, which gives a p-value below 0.001.
Paste the temperatures into the X box and the sales into the Y box in the same order. The result shows the final figures, not this table of working.
Reading the regression equation: slope and intercept
Under r, the result prints the least-squares line ŷ = a + bx, the straight line that keeps the squared vertical distances to the points as small as possible. This is simple linear regression with one predictor, so the page also serves as a line of best fit calculator for straight-line data.
- Slope (b) is Sxy ÷ Sxx, the average change in Y for each one-unit rise in X. For the kiosk, 4,881.43 ÷ 247.43 ≈ 19.73: roughly 20 more ice creams for every extra degree. The slope always has the same sign as r.
- Intercept (a) is ȳ − b × x̄, the value of the line at X = 0. Here it is 403.71 − 19.73 × 22.71 ≈ −44.41.
The equation is sales ≈ −44.41 + 19.73 × temperature, and the line always passes through the point (x̄, ȳ). There is no field for predictions, so substitute by hand: at 25 °C the line gives −44.41 + 19.73 × 25 ≈ 449 ice creams. Only predict inside the range you measured. The negative intercept does not mean minus 44 sales at 0 °C; no data was collected anywhere near freezing.
r squared: the coefficient of determination
r² is the share of the variation in Y that the line accounts for. For the kiosk, r² ≈ 0.9151, so about 92% of the day-to-day variation in sales lines up with temperature. Squaring makes a moderate correlation look modest: an r of 0.5 explains only 25%.
How to interpret a correlation coefficient
The label next to r follows a common rule of thumb:
| Size of r | Label |
|---|---|
| Below 0.2 | Very weak |
| 0.2 to 0.39 | Weak |
| 0.4 to 0.59 | Moderate |
| 0.6 to 0.79 | Strong |
| 0.8 or above | Very strong |
Treat the words as a rough guide. Two checks matter more than the label:
- Outliers. Suppose the kiosk adds an eighth day: 15 °C, but a beach festival brought 640 sales. That one pair drops r from 0.9566 to about 0.4838 and r² from 92% to 23%, and the p-value climbs to about 0.22.
- Curves. r only detects straight-line patterns. The values y = x² for x from −3 to 3 depend perfectly on x, yet r is exactly 0. For x from 1 to 10 the same curve gives r = 0.9746, so a high r does not prove a line is the right model.
Correlation is not causation
A strong r shows that two variables move together, never why. Temperature plausibly drives ice-cream sales, but hot days are also weekends and school holidays more often, and either could explain part of the pattern. Ice-cream sales and drowning incidents both rise in summer, yet neither causes the other. Only a controlled experiment, or a study design that rules out the alternatives, can show cause and effect.
Assumptions and limits
- Pearson only. Spearman's and Kendall's rank correlations are not calculated.
- Straight-line fit only. No exponential or polynomial models, no scatter plot and no confidence interval for r. Draw the scatter plot in a spreadsheet before trusting the number.
- Two lists of equal length, at least three pairs. Two points always lie on a line, so they give r = +1 or −1 and say nothing. If the counts differ, the error message says how many values each box holds.
- The p-value assumes independent pairs that are roughly normal together. Values recorded over time, where each day depends on the last, make it look more convincing than it should.
Frequently asked questions
How do I calculate the correlation coefficient?
Find the mean of X and of Y. For each pair, multiply the deviation of x from its mean by the deviation of y from its mean and add these products to get Sxy. Also add the squared deviations of X (Sxx) and of Y (Syy). Then r = Sxy ÷ √(Sxx × Syy). The calculator does this arithmetic exactly and shows r, r² and the regression line.
What is a good correlation coefficient value?
It depends on the field. A common rule of thumb reads |r| of 0.8 or more as very strong, 0.6 to 0.79 as strong, 0.4 to 0.59 as moderate, 0.2 to 0.39 as weak and below 0.2 as very weak. In physics or engineering, 0.9 may be disappointing; in psychology or economics, 0.3 can be a meaningful finding. Always plot the data as well.
How do I calculate the r squared value?
Square the correlation coefficient. r gives the direction and strength of a straight-line relationship, from −1 to +1. r² (the coefficient of determination) runs from 0 to 1 and is the share of the variation in Y that the regression line accounts for. An r of 0.7 means r² = 0.49, so the line explains about 49% of the variation, not 70%.
What is the difference between Pearson and Spearman correlation?
Pearson's product-moment correlation measures linear association between the raw values, and it is the only one this calculator gives. Spearman's rank correlation applies the same formula to the ranks of the values instead, and suits data that is ordinal or related in a curved but consistently rising or falling way.
How do I find the correlation coefficient in Excel?
Put X in one column and Y in the next, then use =CORREL(range1, range2) or =PEARSON(range1, range2) for r. =RSQ(y_range, x_range) returns r², and =SLOPE(y_range, x_range) and =INTERCEPT(y_range, x_range) give the regression equation. Google Sheets uses the same function names. The figures match the ones shown here, apart from rounding.
What does the p-value tell me?
It is the probability of seeing a correlation at least this far from zero if the true correlation were zero. A p-value below 0.05 is often called statistically significant. With few pairs even a large r can have a high p-value, and with thousands of pairs a tiny, unimportant r can be highly significant, so report r as well as p.
Related calculators
- Slope CalculatorSlope calculator: two points or a rise and run give the slope as a decimal and fraction, plus the angle, percent grade and line equation.
- Standard Deviation CalculatorThis standard deviation calculator (sample vs population) turns a pasted list of numbers into s or σ, with the variance and mean alongside.
- Average CalculatorAn average calculator of numbers in any list: paste or type them to get the mean, median, mode and range in one step.
- Z-Score CalculatorZ-score calculator: percentile, tail probabilities and p-value for any raw score or z-score, or the z-score behind any percentile.
- Confidence Interval CalculatorThis confidence interval calculator for mean values (t or z) and proportions turns summary statistics into lower and upper limits with the margin of error.
Last updated: