Enter your paired data points below. Ensure you have at least two pairs (x, y). For example, if you are correlating advertising spend (X) with sales (Y), enter the spend and sales for the same period in each row.
Please enter valid numerical data for all fields.
You need at least two data pairs (x, y) to calculate correlation.
Pearson Correlation Coefficient (r)
—
Understanding the Coefficient of Correlation
The coefficient of correlation, most commonly the Pearson correlation coefficient (often denoted by 'r'), is a statistical measure that quantifies the strength and direction of a linear relationship between two continuous variables. It tells us how well the two variables move in relation to each other.
What Does the Coefficient of Correlation (r) Tell You?
Range: The value of 'r' always falls between -1 and +1, inclusive.
+1: Indicates a perfect positive linear relationship. As one variable increases, the other increases proportionally.
-1: Indicates a perfect negative linear relationship. As one variable increases, the other decreases proportionally.
0: Indicates no linear relationship between the two variables.
Values between 0 and +1: Indicate a positive linear relationship of varying strength. The closer to +1, the stronger the relationship.
Values between -1 and 0: Indicate a negative linear relationship of varying strength. The closer to -1, the stronger the relationship.
The Math Behind the Calculation
The Pearson correlation coefficient (r) is calculated using the following formula:
xi and yi are the individual data points for the two variables.
x̄ (x-bar) and ȳ (y-bar) are the means (averages) of the x and y variables, respectively.
Σ (Sigma) denotes summation.
Essentially, the formula measures the covariance of the two variables divided by the product of their standard deviations. A positive covariance indicates that the variables tend to move in the same direction, while a negative covariance indicates they tend to move in opposite directions. The division by standard deviations normalizes the measure to be between -1 and +1.
How to Use This Calculator
Enter your first pair of data points (X1, Y1).
Click "Add Another Data Pair" for each subsequent pair of data points (X2, Y2), (X3, Y3), and so on.
Once you have entered all your data pairs, click the "Calculate Correlation" button.
The calculated Pearson correlation coefficient (r) will be displayed.
Use Cases for Correlation Coefficient
Business: Analyzing the relationship between marketing spend and sales, or customer satisfaction scores and customer retention.
Finance: Measuring how two stock prices move together, or the relationship between interest rates and bond prices.
Science: Studying the link between drug dosage and patient response, or environmental factors and species population.
Social Sciences: Investigating correlations between education levels and income, or study hours and exam scores.
Health: Examining the relationship between exercise frequency and blood pressure, or diet and weight change.
Remember, correlation does not imply causation. Just because two variables are correlated does not mean one causes the other; there might be a third, unmeasured variable influencing both.
var pairCount = 1;
function addInputPair() {
pairCount++;
var dataInputGroups = document.getElementById('dataInputGroups');
var newXGroup = document.createElement('div');
newXGroup.className = 'input-group';
newXGroup.innerHTML = '' +
";
var newYGroup = document.createElement('div');
newYGroup.className = 'input-group';
newYGroup.innerHTML = '' +
";
dataInputGroups.appendChild(newXGroup);
dataInputGroups.appendChild(newYGroup);
}
function calculateCorrelation() {
var xValues = [];
var yValues = [];
var inputs = document.querySelectorAll('#dataInputGroups input[type="number"]');
var i;
for (i = 0; i < inputs.length; i++) {
var value = parseFloat(inputs[i].value);
if (isNaN(value)) {
document.getElementById('inputError').style.display = 'block';
document.getElementById('insufficientDataError').style.display = 'none';
document.getElementById('resultSection').style.display = 'none';
return;
}
if (inputs[i].id.startsWith('x')) {
xValues.push(value);
} else {
yValues.push(value);
}
}
document.getElementById('inputError').style.display = 'none';
if (xValues.length < 2) {
document.getElementById('insufficientDataError').style.display = 'block';
document.getElementById('resultSection').style.display = 'none';
return;
}
document.getElementById('insufficientDataError').style.display = 'none';
var n = xValues.length;
var sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0, sumY2 = 0;
for (i = 0; i < n; i++) {
sumX += xValues[i];
sumY += yValues[i];
sumXY += xValues[i] * yValues[i];
sumX2 += xValues[i] * xValues[i];
sumY2 += yValues[i] * yValues[i];
}
var numerator = n * sumXY – sumX * sumY;
var denominatorX = n * sumX2 – sumX * sumX;
var denominatorY = n * sumY2 – sumY * sumY;
// Handle cases where variance is zero for one or both variables
if (denominatorX === 0 || denominatorY === 0) {
document.getElementById('correlationResult').innerText = 'Undefined (Zero Variance)';
document.getElementById('resultSection').style.display = 'block';
return;
}
var denominator = Math.sqrt(denominatorX * denominatorY);
var correlation = numerator / denominator;
document.getElementById('correlationResult').innerText = correlation.toFixed(4);
document.getElementById('resultSection').style.display = 'block';
}