What Correlation Measures and Why You Calculate It
Correlation is a number that tells you how strongly two sets of data move together. If one goes up and the other tends to go up too, they have positive correlation. If one goes up while the other tends to go down, they have negative correlation. If they move independently, correlation is near zero.
You calculate correlation when you want to know whether a relationship exists between two variables — for example, whether hours studied and test scores move together, or whether temperature and ice cream sales track each other. The result is a single number between −1 and +1 that summarizes the strength and direction of that relationship.
The most common type is Pearson correlation, which measures linear relationships (straight-line patterns). This is what most people mean when they say "correlation" without qualification.
Key Takeaways
- Pearson correlation produces a number from −1 to +1: positive values mean both variables rise together, negative values mean one rises as the other falls, and values near zero mean no linear relationship.
- You need two columns of paired data (same number of observations in each), and both variables should be numeric rather than categories.
- The calculation involves finding how far each data point sits from its average, multiplying those distances for each pair, and dividing by the standard deviations of both variables.
- Most spreadsheet programs and statistical software compute correlation with a single function, so you rarely calculate by hand unless you are learning the concept.
- A strong correlation number does not prove that one variable causes the other — it only shows they move together.
Preparing Your Data for Correlation
Before you calculate, organize your data into two columns with the same number of rows. Each row should represent one observation or case. For example, if you are correlating study hours with test scores, one row might be "Student A: 5 hours, 78 points." The next row is "Student B: 3 hours, 62 points," and so on.
Both variables must be numeric — actual numbers you can add and divide, not categories like "high," "medium," or "low." If your data includes text labels or missing values (blank cells), remove those rows or convert the labels to numbers first. Correlation cannot work with incomplete pairs.
Check that your data makes sense. If one variable is temperature in Fahrenheit and the other is ice cream sales in dollars, that is fine — correlation works across different units. But if one column contains dates and the other contains names, correlation is not the right tool.
The Formula Behind Correlation
Pearson correlation uses this formula:
r = (sum of products of deviations) / (product of standard deviations × number of pairs)
In plainer terms: for each data point, you find how far it sits from the average of its variable. You multiply those distances for each pair. You add all those products together. Then you divide by the standard deviations of both variables multiplied by each other and by the count of pairs.
The result, called r, ranges from −1 to +1. An r of +1 means perfect positive correlation (one variable rises exactly as the other rises). An r of −1 means perfect negative correlation (one rises exactly as the other falls). An r of 0 means no linear relationship.
In practice, you almost never compute this by hand. Spreadsheets and statistics programs do it when ready and with fewer errors than manual calculation.
Computing Correlation in a Spreadsheet
In Microsoft Excel or Google Sheets, use the CORREL function. Type the formula as =CORREL(range1, range2), where range1 is your first column of data and range2 is your second column. For example, if study hours are in cells A2 through A20 and test scores are in B2 through B20, type =CORREL(A2:A20, B2:B20) and press Enter.
Google Sheets also accepts PEARSON as a function name that does the same thing: =PEARSON(A2:A20, B2:B20). Both return the same result.
The function returns a single number. If it is 0.87, the variables have strong positive correlation. If it is −0.42, they have moderate negative correlation. If it is 0.05, they have almost no linear relationship.
Make sure both ranges have the same number of cells. If one range has 19 cells and the other has 20, the function will return an error. Also verify that the ranges contain only numbers — if a cell holds text, the function may skip that row or return an error depending on the software.
Computing Correlation in Statistical Software
In R, the language used by statisticians and data analysts, use the cor() function. Type cor(variable1, variable2) where variable1 and variable2 are your two data columns. R returns the correlation coefficient when ready.
In Python with the pandas library, load your data into a DataFrame and use the corr() method. Type dataframe.corr() to see correlations between all numeric columns at once, or dataframe['column1'].corr(dataframe['column2']) to compute correlation between two specific columns.
In SPSS (a point-and-click statistics program), go to Analyze → Correlate → Bivariate, select your two variables, and click OK. SPSS displays the correlation coefficient and a p-value that tells you whether the relationship is statistically meaningful or likely due to chance.
Interpreting the Correlation Number
A correlation of +0.9 to +1.0 or −0.9 to −1.0 indicates very strong correlation. A correlation of +0.7 to +0.9 or −0.7 to −0.9 indicates strong correlation. A correlation of +0.5 to +0.7 or −0.5 to −0.7 indicates moderate correlation. A correlation of +0.3 to +0.5 or −0.3 to −0.5 indicates weak correlation. A correlation between −0.3 and +0.3 indicates little to no linear relationship.
These ranges are rough guidelines, not hard rules. In some fields, a correlation of 0.6 is considered strong; in others, 0.8 is the threshold. The context of your data matters.
Remember that correlation measures only linear relationships — straight-line patterns. Two variables can move together in a curved or zigzag way and still show low correlation. For example, a car's speed and fuel efficiency might have a curved relationship (efficiency peaks at a certain speed, then drops), but Pearson correlation might show only weak connection.
Common Mistakes to Avoid
Do not assume correlation means causation. If ice cream sales and drowning deaths are correlated, it is because both rise in summer, not because ice cream causes drowning. Always think about whether a third variable (in this case, warm weather) might explain both.
Do not use correlation on data that is not numeric. If you try to correlate zip codes with income, the result is meaningless because zip codes are labels, not quantities. Convert categorical data to numbers only if the numbers represent a real order or scale.
Do not ignore outliers without reason. A single extreme data point can pull the correlation number up or down. If you have an outlier, investigate whether it is a data entry error or a real observation. If it is real, report the correlation both with and without it.
Do not forget to check that your data is paired correctly. If you accidentally sort one column but not the other, the correlation will be wrong. Make sure each row represents the same case or observation across both columns.
Frequently Asked Questions
What is the difference between correlation and causation?
Correlation tells you that two variables move together. Causation means one variable directly causes the other to change. A strong correlation does not prove causation — there may be a third variable affecting both, or the relationship may be coincidence. You need additional evidence (experiments, logic, domain knowledge) to claim causation.
Can correlation be greater than 1 or less than −1?
No. Pearson correlation always falls between −1 and +1. If your software returns a number outside this range, there is an error in the data or the calculation. Check for missing values, non-numeric entries, or mismatched column lengths.
What does a correlation of zero mean?
A correlation near zero means there is no linear relationship between the two variables — they do not tend to move together in a straight-line pattern. This does not mean they are unrelated; they may have a curved or complex relationship that Pearson correlation does not detect.
Should I use Pearson correlation for all data?
Pearson correlation works best for continuous numeric data with a roughly linear relationship. If your data is ranked (like "1st place, 2nd place, 3rd place"), use Spearman correlation instead. If your data is categorical or has a strong curved pattern, other methods may be more appropriate.
How many data points do I need to calculate correlation?
Technically, you need at least two pairs of data points. In practice, correlation from only two or three pairs is unreliable and meaningless. Most statisticians recommend at least 30 pairs to get a stable estimate, though the exact number depends on how much noise is in your data.