ThisCalculator

Statistics

Correlation Coefficient: Formula and Calculation

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Correlation Coefficient: Formula and Calculation

A correlation coefficient measures the direction and strength of a relationship between paired numerical values; this calculator computes Pearson’s correlation coefficient, r. Enter two equally sized, comma-separated lists of numbers, and it returns r from −1 to +1, along with the number of pairs.

Formula

Pearson’s correlation coefficient is the covariance of two variables divided by the product of their standard deviations. An equivalent computational formula is:

r = [nΣ(xiyi) − (Σxi)(Σyi)] / √{[nΣ(xi2) − (Σxi)2][nΣ(yi2) − (Σyi)2]}

  • xi and yi are the two measurements in pair i; their units may differ.
  • n is the number of complete pairs, a count.
  • Σ means to add the indicated values across all pairs. For example, Σ(xiyi) adds each pair’s product.
  • r is dimensionless: the units cancel, so the result has no measurement unit.

The expression in the calculator uses n = 5, matching the five default entries in each list. The coefficient is defined when both lists vary; if either list is constant, its standard deviation is zero and correlation is undefined.

Worked Example

Using the default lists, the five pairs are (1, 2), (2, 4), (3, 5), (4, 4), and (5, 5). The calculator retains the pairing by position: the first value in X goes with the first value in Y, and so on.

  • n = 5; Σx = 15; Σy = 20.
  • Σ(xy) = 1×2 + 2×4 + 3×5 + 4×4 + 5×5 = 66.
  • Σ(x2) = 55 and Σ(y2) = 86.
  • Numerator = 5×66 − 15×20 = 30.
  • Denominator = √[(5×55 − 152)(5×86 − 202)] = √[(50)(30)] = √1500.
  • r = 30/√1500 ≈ 0.77; to two decimal places, the result is 0.77.

The calculator therefore reports a Pearson correlation coefficient of 0.77 and 5 pairs. This is a positive association in these data, not a guarantee that every increase in X corresponds to an increase in Y.

How to Enter Data and Read the Result

Put numbers in each list separated by commas. Both lists must have the same number of entries, and each position must describe one observation’s two measurements. Do not sort one list independently: doing so changes the pairs and may change the correlation.

Values near +1 indicate a strong positive linear association; values near −1 indicate a strong negative linear association. A value near 0 indicates little or no linear association. These are descriptions of linear pattern, not universal thresholds for “strong” or “weak”; interpretation depends on the context and data quality. The sign gives direction, while the distance from zero gives the strength of the linear relationship.

When Pearson Correlation Is Useful

Use Pearson’s r when you want to summarize how two quantitative variables move together in a roughly linear way—for example, paired measurements such as hours studied and test scores, or a machine setting and its measured output. It is useful for an initial description of association, not by itself for prediction, causal claims, or decisions about whether a pattern matters practically.

A scatterplot is an important companion to the coefficient. It can reveal curvature, clusters, or unusual observations that a single number conceals. A curved relationship can be strong and systematic while Pearson’s r is close to zero, because the measure captures linear association specifically.

Common Mistakes and Limitations

  • Unequal list lengths: every X value needs a matching Y value. Exclude incomplete pairs consistently rather than shifting entries to force a match.
  • Confusing correlation with causation: association alone does not show that one variable causes the other. A third variable, selection effects, or chance may help explain a pattern.
  • Overlooking outliers: one unusual pair can substantially change Pearson’s r. Check the underlying observations and plot the data before interpreting the result.
  • Treating zero as no relationship: zero means no linear correlation in the data. A nonlinear pattern may still exist.
  • Rounding too soon: calculate from the original values and round only the final coefficient. The displayed two decimals are a concise summary, not the full computed value.
  • Using constant data: if all values in either variable are identical, its standard deviation is zero and the coefficient cannot be calculated.

Pearson correlation is sensitive to the numerical scale in the sense that extreme observations can affect it, but changing units by a positive linear conversion—for example, metres to centimetres—does not change r. Reversing one variable’s direction changes the sign. The coefficient also says nothing about the slope of a relationship or the size of changes in the original units.

Frequently Asked Questions

How do you calculate the correlation coefficient by hand?
Pair the observations, calculate the sums in the Pearson formula, and divide its numerator by the square root of the product of the two adjusted sums of squares. The worked example above shows each step.

What does a correlation coefficient of 0.77 mean?
It indicates a positive linear association: larger values of one variable tend to accompany larger values of the other in the observed data. Its practical importance depends on context, sample size, and the pattern shown in a plot.

Can a correlation coefficient be greater than 1?
No. Pearson’s coefficient ranges from −1 to +1, inclusive, when it is defined. A result outside that range usually points to a calculation or data-entry error.

Does a correlation of zero mean the variables are unrelated?
No. It means there is no linear correlation, but a nonlinear relationship may be present. Plot the paired observations to check for curves or other structure.

What if the two lists have different numbers of values?
Correlation needs matched pairs, so the lists must have equal lengths. Identify which observations genuinely belong together and handle missing values without changing the alignment.

Related

Formula used
list x | X values | 1, 2, 3, 4, 5
list y | Y values | 2, 4, 5, 4, 5
out r | Pearson correlation coefficient | - | (5*sum(x*y)-sum(x)*sum(y))/sqrt((5*sum(x^2)-sum(x)^2)*(5*sum(y^2)-sum(y)^2)) | 2
out n | Number of pairs | - | count(x) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.