Correlation and Regression
Whenever two things seem to move together — hours studied and exam scores, height and weight, advertising spend and sales — we naturally want to know two things: how strongly are they linked, and can I use one to predict the other? Correlation answers the first question with a single number between and . Regression answers the second by fitting the "best" straight line through the cloud of data. Together they are among the most-used tools in all of science, economics, and machine learning — and among the most-abused, because a strong relationship is endlessly mistaken for a causal one.
This page teaches you to read a scatterplot, compute and interpret the correlation coefficient , build the least-squares regression line by hand, use it to predict, and — crucially — to know when your prediction is trustworthy and when the whole thing is a mirage.
Learning Objectives
- Read and describe the pattern in a scatterplot (direction, form, strength, outliers).
- Compute the Pearson correlation coefficient and interpret its sign and magnitude.
- Derive and calculate the least-squares regression line .
- Use a regression line to make predictions and understand interpolation vs. extrapolation.
- Interpret the slope, intercept, and coefficient of determination in context.
- Explain clearly why correlation does not imply causation, with lurking variables.
Quick Answer
Correlation measures the strength and direction of a linear relationship between two quantitative variables using , which ranges from (perfect negative) through (no linear relationship) to (perfect positive). The least-squares regression line is the unique straight line that minimizes the sum of squared vertical distances from the points; its slope is and it always passes through the mean point . The square of the correlation, , tells you the fraction of variation in explained by . You can predict from within the range of your data, but a strong never proves that causes — a hidden third variable or reverse causation can produce the same pattern.
Where It Came From
Regression was born from an obsession with heredity. In the 1870s and 1880s the Victorian polymath Francis Galton — cousin of Charles Darwin — wanted to understand how traits like height passed from parents to children. He collected the heights of hundreds of parents and their grown children and plotted them. He noticed something strange: tall parents did tend to have tall children, but the children were on average closer to the population mean than their parents were. Exceptionally tall parents had children shorter than themselves; exceptionally short parents had children taller than themselves. Galton called this pull toward the average "regression toward mediocrity" (today: regression to the mean). The line he drew through his data to summarize the parent–child relationship became the first "regression line," and the name stuck to the entire method — an accident of biological history.
Galton had the picture but lacked the mathematics to measure the strength of such relationships precisely. That was supplied by his younger colleague Karl Pearson around 1895–1896. Building on earlier work by the French physicist Auguste Bravais, Pearson formalized the product-moment correlation coefficient — the standardized measure we still use — giving science a single, dimensionless number to quantify association. The deep need these tools answered was universal: nature is noisy. Two quantities rarely line up perfectly, so researchers needed a rigorous way to say "these vary together, and here is exactly how much" rather than relying on gut impression. That need — measuring imperfect relationships in messy data — is why correlation and regression became the backbone of modern statistics.
Scatterplots: Seeing the Relationship First
Before any calculation, plot the data. A scatterplot puts one variable on the horizontal axis (, the explanatory or independent variable) and the other on the vertical axis (, the response or dependent variable). Each observation is one dot. When you look at a scatterplot, describe four things:
- Direction — positive (up to the right), negative (down to the right), or none.
- Form — linear, curved, or clustered.
- Strength — how tightly points hug an imagined line.
- Outliers — points far from the overall pattern.
This step is not optional decoration. The correlation coefficient only measures linear strength, so a perfect U-shaped parabola can have near despite a flawless relationship. The famous Anscombe's quartet consists of four datasets with identical , identical regression lines, and identical means — yet radically different scatterplots (one is curved, one is dominated by a single outlier). The lesson: numbers summarize, but the picture reveals.
The Correlation Coefficient r
Pearson's standardizes both variables and averages the products. The most transparent formula is
where and are the sample standard deviations. Each factor is a z-score. When a point is above average in both and , the product is positive; when it is above in one and below in the other, the product is negative. Add these up and captures whether points tend to be "on the same side" of both means.
Key properties:
- always.
- has no units and is unchanged if you rescale (e.g., cm to inches).
- is symmetric: the correlation of with equals that of with .
- only measures linear association and is sensitive to outliers.
Worked Example: Computing r
Suppose five students report hours studied () and their test score ():
| Student | (hours) | (score) |
|---|---|---|
| A | 1 | 50 |
| B | 2 | 60 |
| C | 3 | 70 |
| D | 4 | 65 |
| E | 5 | 80 |
Means: and .
Build a table of deviations. Let and :
Sums: , , .
An of about signals a strong positive linear relationship: more study hours go with higher scores.
Least-Squares Regression Lines
Correlation says how strong; regression gives the actual line so we can predict. We write the fitted line as
where (read "y-hat") is the predicted value. For any real point, the residual is , the vertical miss. The least-squares line is the one choice of and that makes as small as possible. Squaring keeps positive and negative misses from cancelling and punishes big misses harder. Solving that minimization (via calculus) gives clean formulas:
The second form of the slope is beautiful: it links regression directly to correlation. Because , the line is forced to pass through the mean point — a fact worth remembering.
Worked Example: Fitting the Line
Using the same study data, we already have and . So
The regression line is
Interpreting the slope: each additional hour of study is associated with about more points on the test. Interpreting the intercept: a student who studies hours is predicted to score — plausible here, but often the intercept is just a mathematical anchor with no real meaning.
Prediction, and Its Limits
To predict the score for a student who studies hours:
This is interpolation — predicting inside the observed range ( to hours) — and is reasonable. Predicting for hours (, an impossible score above ) is extrapolation: assuming the linear pattern continues far beyond the data. It rarely does, and it is one of the most common ways predictions go badly wrong.
r-squared: How Much Does the Line Explain?
The coefficient of determination is the fraction of the variation in that is explained by the linear relationship with . Here , so about 85% of the variation in test scores is accounted for by study hours; the remaining is other factors (sleep, prior knowledge, luck). Values of range from to , and it is often more meaningful to report than itself because it has a concrete "proportion of variance" interpretation.
Correlation Versus Causation
This is the single most important idea on the page. A strong tells you two variables move together; it says nothing about why. There are always three possible explanations for an observed correlation between and :
- causes (what people assume).
- causes (reverse causation).
- A lurking (confounding) variable causes both.
Classic illustration: across a town, ice cream sales correlate strongly with drowning deaths. Ice cream does not cause drowning. The lurking variable is hot weather — heat drives both more ice cream buying and more swimming. Another: children with bigger shoe sizes read better. Shoes do not cause literacy; age confounds both. Only a well-designed randomized controlled experiment — where the researcher randomly assigns the value of — can establish causation, because randomization breaks the link to lurking variables. Observational correlation, no matter how strong, cannot.
Real-World Applications
- Medicine: regression relates drug dosage to blood pressure response; but establishing that a drug works requires randomized trials, not just correlation.
- Economics and finance: the "beta" of a stock is a regression slope measuring how the stock moves relative to the market. Analysts regress consumer spending on income.
- Machine learning: linear regression is the foundational predictive model, and least squares underlies much of modern data science.
- Sports analytics: teams regress player statistics (on-base percentage, expected goals) to predict future performance and set salaries.
- Public health: the smoking–lung cancer link began as a correlation; it took decades of converging evidence and mechanism studies to firmly establish causation.
Common Mistakes
Mistake 1: Concluding causation from correlation. A student sees between two variables and writes " causes ." Why it's wrong: correlation is symmetric and blind to mechanism; a lurking variable or reverse causation can produce identical numbers. Correction: say the variables are "associated" or "related," and reserve causal language for experimental evidence.
Mistake 2: Trusting without plotting the data. A dataset with a clear curve or one dominant outlier can yield a misleading . Why it's wrong: only measures linear strength; a parabola can have despite a perfect relationship. Correction: always inspect the scatterplot before and after computing (remember Anscombe's quartet).
Mistake 3: Extrapolating beyond the data. Using to predict a score for study hours gives an impossible . Why it's wrong: the linear pattern was only observed from to hours; nothing guarantees it holds outside that range. Correction: restrict predictions to the observed range of , and flag any extrapolation as speculative.
Comparison and Connections
Correlation and regression are two views of the same relationship, but they are not interchangeable.
| Feature | Correlation () | Regression () |
|---|---|---|
| Question answered | How strong/what direction? | Predict from ? |
| Output | One number, to | A line (slope and intercept) |
| Units | None (dimensionless) | Slope has units of per |
| Symmetry | Symmetric in and | Not symmetric — on differs from on |
| Requires which is "response"? | No | Yes |
They connect through and . Note the asymmetry of regression: the line predicting scores from hours is not the same as the line predicting hours from scores, even though is identical both ways. Correlation is also related to covariance — is just covariance standardized by both standard deviations, which strips out the units.
Practice Questions
Recall
What is the range of possible values for the correlation coefficient , and what do the endpoints mean? Answer: ranges from to . A value of is a perfect positive linear relationship, a perfect negative one, and no linear relationship.
Understanding
Explain why the least-squares line uses squared residuals rather than just the sum of residuals. Answer: The plain sum of residuals is always zero for the best line, so it cannot distinguish good fits from bad. Squaring makes all terms positive (preventing cancellation) and penalizes large misses more heavily, yielding a unique, well-behaved minimum.
Application
For a dataset, , , , , and . Find the regression line. Answer: . Then . Line: .
Analysis
A study finds that cities with more police officers have more crime (). Does hiring police cause crime? Explain. Answer: No. This is almost certainly a lurking-variable effect: larger cities have both more crime and more police. Population confounds both variables. Reverse causation is also plausible (high-crime cities hire more police). Correlation cannot settle causation; only a controlled study could.
FAQ
Is "strong"? It depends on the field. In physics, might be weak; in social science, where human behavior is noisy, it can be meaningful. As a rough guide: near is weak, moderate, or above fairly strong — but always judge in context and via .
What's the difference between and ? carries the sign (direction) and measures linear strength; (always to ) is the proportion of variance in explained by . Because squaring shrinks values below , gives — only about half the variation explained, which surprises many students.
Why does the regression line always go through ? Because the intercept is defined as . Substituting gives . The mean point is the balance point of the line.
Can I have a strong relationship with ? Yes, if the relationship is nonlinear. A perfect symmetric U-shape (like centered on zero) has because only detects linear trends. Always look at the scatterplot.
Which variable goes on the x-axis? The explanatory (independent) variable — the one you think explains or predicts the other. The response (dependent) variable goes on the y-axis. In study-hours vs. score, hours is explanatory. Getting this backwards changes the regression line.
Quick Revision
- Scatterplot first: describe direction, form, strength, outliers.
- Correlation: , ranges to , unitless, measures linear strength only.
- Regression line: with and ; always passes through .
- Least squares minimizes .
- = proportion of variation in explained by .
- Interpolate (inside data range) safely; never extrapolate blindly.
- Correlation is not causation — beware lurking variables and reverse causation.
- History: Galton (regression to the mean, 1880s), Pearson (the coefficient , 1890s).
Related Topics
Prerequisites
- Statistics and Probability overview
- Descriptive statistics: mean and standard deviation
- Reading and building graphs and coordinate plots
Related Topics
- Covariance and standardization (z-scores)
- Sampling and experimental design (why randomization enables causal claims)
Next Topics
- Multiple regression and the basics of predictive modeling
- Hypothesis testing for the significance of a correlation