PUBH-311 · Lesson 8 of 12 · 21 min

Correlation and simple linear regression

▶ Video coming soon A video version of this lesson is on the way.

A community health nurse running blood pressure clinics in Kestrel Valley’s seniors’ centers and workplaces wanted a simple way to explain to clients why checks become more important with age. She sent Jonah blood pressure readings from ten clients of different ages, chosen to span the range she saw. He plotted them: the points drifted upward from left to right, with plenty of scatter. “Can you put a number on it?” she asked. Jonah calculated two: a correlation coefficient that described how closely the points followed a line, and a regression slope that described how much blood pressure rose, on average, with each additional year of age. They answered different questions, and the nurse needed both.

Earlier lessons compared groups. This lesson turns to relationships between two numerical variables. We cover scatterplots, the Pearson and Spearman correlation coefficients, the least-squares regression line, the interpretation of slope and intercept, the coefficient of determination, inference about the slope, the assumptions of linear regression and how to check them, and the classic traps of correlation and causation.

Scatterplots

The first step in studying the relationship between two numerical variables is always a scatterplot, with one point per observation. By convention, the explanatory variable (predictor, independent variable) goes on the horizontal x-axis and the response variable (outcome, dependent variable) on the vertical y-axis. Look for four features: the direction (positive if y tends to rise with x, negative if it falls), the form (linear, curved or no clear pattern), the strength (how tightly the points cluster around the pattern) and any outliers or unusual points.

Table 1. Age and systolic blood pressure for ten clinic clients (invented data).
Client12345678910
Age (years)25323841455055616672
Systolic BP (mmHg)115124117128121133122139129142

The scatterplot of these data (Figure 1, later in the lesson) shows a positive, roughly linear relationship of moderate to strong strength, with no extreme outliers.

The Pearson correlation coefficient

The Pearson correlation coefficient, \(r\), measures the strength and direction of a linear relationship between two numerical variables. It ranges from −1 to +1. A value of +1 means all points lie exactly on an upward-sloping line, −1 means they lie exactly on a downward-sloping line, and 0 means no linear relationship. Rough descriptive labels are sometimes attached (for example, values around 0.1 described as weak, 0.3 moderate and 0.5 or more strong in much social and health research), but what counts as strong depends on the field.

The formula uses sums of squares and cross-products about the means:

\[r = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum (x_i - \bar{x})^2 \sum (y_i - \bar{y})^2}} = \frac{S_{xy}}{\sqrt{S_{xx} S_{yy}}}\]

Points in the upper-right and lower-left quadrants relative to the means contribute positive products; points in the other two quadrants contribute negative products. If positive products dominate, \(r\) is positive.

Correlation has several properties worth remembering. It has no units and does not change if you change the units of measurement (age in months instead of years). It is symmetric: the correlation of x with y equals that of y with x. It measures only linear association: a perfect U-shaped relationship can have \(r = 0\). And it is sensitive to outliers; a single extreme point can create or destroy a strong correlation.

The statistician Francis Anscombe made this last point memorably in 1973 with four small data sets, now called Anscombe’s quartet, that share almost exactly the same means, standard deviations, correlation (0.82) and regression line, yet look completely different when plotted: one linear, one curved, one with a single outlier and one with all but one point at the same x value. The lesson is simple: always plot the data.

Spearman’s rank correlation

Spearman’s rank correlation coefficient, \(r_s\) (or rho), is the Pearson correlation calculated on the ranks of the data rather than the raw values. It measures the strength of a monotonic relationship, one that consistently increases or decreases but not necessarily in a straight line. It is resistant to outliers and suitable for ordinal data or skewed numerical data. For the clinic data, Spearman’s coefficient is 0.78, almost the same as Pearson’s.

Simple linear regression

Correlation describes how closely points follow a line; regression describes the line itself and lets us predict the response from the explanatory variable. Simple linear regression models the mean of the outcome \(y\) as a straight-line function of one predictor \(x\):

\[y = \beta_0 + \beta_1 x + \varepsilon\]

Here \(\beta_0\) is the intercept, the mean of \(y\) when \(x = 0\); \(\beta_1\) is the slope, the change in the mean of \(y\) for a one-unit increase in \(x\); and \(\varepsilon\) (epsilon) is the random error, the scatter of individual values around the line. We estimate \(\beta_0\) and \(\beta_1\) from data, writing the estimates as \(b_0\) and \(b_1\), and the fitted line as \(\hat{y} = b_0 + b_1 x\).

The method of least squares

Many lines could be drawn through a cloud of points. The standard choice is the least-squares line, which makes the sum of squared vertical distances between the points and the line as small as possible. Each vertical distance is a residual: the observed value minus the value predicted by the line, \(e_i = y_i - \hat{y}_i\). The least-squares estimates are

\[b_1 = \frac{S_{xy}}{S_{xx}}, \qquad b_0 = \bar{y} - b_1 \bar{x}\]

The least-squares line always passes through the point \((\bar{x}, \bar{y})\). The method dates to the early 19th century, when Adrien-Marie Legendre and Carl Friedrich Gauss used it to fit astronomical observations. The word "regression" itself comes from Francis Galton, who in the 1880s noticed that tall parents tended to have children who were tall but closer to the average, and called it "regression toward mediocrity," the same regression to the mean met in Lesson 5.

Worked problem

Fitting the regression line for age and blood pressure

Using the ten clients in Table 1, calculate the correlation coefficient and the least-squares regression line for predicting systolic blood pressure from age. The means are 48.5 years and 127.0 mmHg; \(S_{xx} = 2062.5\), \(S_{yy} = 724.0\) and \(S_{xy} = 964.0\).

Show solution
  1. Correlation: \(r = 964.0 / \sqrt{2062.5 \times 724.0} = 964.0 / 1222.0 = 0.789\).
  2. Slope: \(b_1 = 964.0 / 2062.5 = 0.467\) mmHg per year.
  3. Intercept: \(b_0 = 127.0 - 0.467 \times 48.5 = 104.3\) mmHg.
  4. Fitted line: predicted SBP = 104.3 + 0.467 × age.
  5. Prediction for a 60-year-old: 104.3 + 0.467 × 60 = 132.4 mmHg.

Answer: r = 0.79, a fairly strong positive linear relationship. The line predicts SBP = 104.3 + 0.47 × age: on average, systolic pressure is about 0.47 mmHg higher for each additional year of age, or about 4.7 mmHg per decade. A typical 60-year-old in this group is predicted to have SBP of about 132 mmHg.

A scatterplot of systolic blood pressure against age for ten clients, with points rising from about 115 mmHg at age 25 to 142 mmHg at age 72. A fitted line, predicted SBP equals 104.3 plus 0.47 times age, runs through the points, and dotted vertical segments from each point to the line show the residuals. The annotation gives r equals 0.79 and r squared equals 0.62.
Figure 1. Least-squares regression of systolic blood pressure on age. Residuals are the vertical distances from the points to the line.

Interpreting the slope and intercept

The slope is the key quantity. Interpret it in the units of both variables and as a statement about averages: "Among clients like these, each additional year of age is associated with a 0.47 mmHg higher mean systolic pressure." Avoid causal language such as "aging raises blood pressure by 0.47 mmHg a year" unless the study design supports it; these are cross-sectional data comparing different people of different ages, not following individuals over time.

The intercept is the predicted value when \(x = 0\). Here that is a newborn’s predicted adult blood pressure, which is meaningless, because no one younger than 25 was studied. Intercepts often lack a sensible interpretation; they are needed to position the line. Analysts sometimes center a predictor by subtracting a meaningful value (for example, age minus 50) so that the intercept becomes the predicted value at that point.

Prediction and extrapolation

Predictions are most trustworthy within the range of the data used to fit the line. Extrapolation, predicting outside that range, assumes the linear relationship continues, which may not be true. Using the clinic line to predict blood pressure at age 5 or age 100 would be unwise.

How well does the line fit?

The coefficient of determination, \(r^2\), is the proportion of the variation in \(y\) that is explained by its linear relationship with \(x\). In simple linear regression it equals the square of the correlation coefficient. For the clinic data, \(r^2 = 0.789^2 = 0.62\): age explains about 62 percent of the variation in systolic pressure among these ten clients, and the remaining 38 percent reflects other factors and measurement variability.

The residual standard deviation \(s\), sometimes called the root mean squared error, describes the typical size of the residuals: \(s = \sqrt{\sum e_i^2 / (n - 2)}\). For the clinic data the residual sum of squares is 273.4, so \(s = \sqrt{273.4/8} = 5.8\) mmHg; actual readings typically lie within about 6 mmHg of the line. We divide by \(n - 2\) because two parameters, the slope and intercept, were estimated.

Inference about the slope

The ten clients are a sample. Would the relationship hold in the wider population? We test the null hypothesis \(H_0: \beta_1 = 0\) (no linear relationship) using

\[t = \frac{b_1}{SE(b_1)}, \qquad SE(b_1) = \frac{s}{\sqrt{S_{xx}}}\]

with \(n - 2\) degrees of freedom. For the clinic data, \(SE(b_1) = 5.85/\sqrt{2062.5} = 0.129\), so \(t = 0.467/0.129 = 3.63\) with 8 df, giving p = 0.007. A 95 percent confidence interval for the slope is \(0.467 \pm 2.306 \times 0.129\), or 0.17 to 0.76 mmHg per year. The test of zero slope is equivalent to testing whether the population correlation is zero.

Statistical software reports these quantities in a standard table. Learning to read it is one of the most useful skills in this course.

Table 2. Regression output for systolic blood pressure on age (n = 10; residual SD 5.85; r² = 0.62).
TermEstimateStd. errortp-value95 percent CI
Intercept104.336.5116.02< 0.00189.3 to 119.3
Age (years)0.4670.1293.630.0070.17 to 0.76

Assumptions and diagnostics

Inference from linear regression rests on four assumptions, often remembered by the acronym LINE:

  • Linearity: the mean of y changes linearly with x.
  • Independence: the observations (and residuals) are independent of one another.
  • Normality: for any value of x, the residuals are approximately normally distributed.
  • Equal variance (homoscedasticity): the spread of residuals is about the same at all values of x.

These are checked mainly by plotting the residuals. A plot of residuals against fitted values should show a random, even band around zero. A curved pattern suggests non-linearity, perhaps needing a transformed or squared term. A funnel shape, with residuals spreading out as fitted values increase, suggests unequal variance, common with costs and other right-skewed outcomes; a log transformation of y may help. A normal quantile plot of residuals checks normality, though with moderate samples the slope estimate is robust to mild non-normality, thanks to the central limit theorem. Independence is judged from the study design; repeated measurements on the same people, or people clustered in families or neighborhoods, violate it.

Watch also for influential points, observations whose removal would substantially change the line. Points with extreme x values have high leverage and can pull the line toward them. Measures such as Cook’s distance flag them. As with outliers in Lesson 2, the response is to investigate, not to delete automatically.

Correlation, causation and ecological fallacies

A strong correlation, however significant, does not establish that one variable causes the other. The association may arise from confounding by a third variable (ice cream sales and drownings both rise in summer), from reverse causation (people with early, undiagnosed illness may lose weight, making low weight appear to cause death), from selection, or from chance. Principles of Epidemiology introduced the Bradford Hill considerations for judging causation from observational data; regression is a tool for estimating associations, and multiple regression (Lesson 9) helps control measured confounders, but neither removes the need for careful design and judgment.

Another trap is the ecological fallacy: inferring individual-level relationships from group-level data. A famous early example is the strong correlation across countries between national fat consumption and breast cancer rates, which did not hold up as strongly when individuals were studied directly. A correlation between neighborhood income and neighborhood asthma rates does not tell us that lower-income individuals within each neighborhood have more asthma. Group-level analyses are valuable, especially for policy questions, but the unit of analysis must match the unit of inference.

Finally, restricting the range of x reduces correlation. If the clinic had studied only clients aged 40 to 50, the correlation between age and blood pressure would have been much weaker, not because the relationship had changed but because the range of ages was narrow.

Back to the clinic

The nurse’s new handout said that, among the clients studied, systolic pressure was about 5 mmHg higher for each decade of age, and showed the scatterplot. She was careful to describe it as a pattern among people of different ages, not a guarantee for any individual, and the handout pointed out the wide scatter: some 70-year-olds had lower readings than some 40-year-olds. Jonah added a footnote that ten clients were too few for precise estimates and that larger surveys should be consulted for population figures.

Common mistakes

  • MistakeCalculating a correlation without plotting the data.

    InsteadAlways draw a scatterplot; non-linear patterns and outliers can make r misleading.

  • MistakeInterpreting r = 0 as "no relationship."

    Insteadr = 0 means no linear relationship; a strong curved relationship can still exist.

  • MistakeDescribing a regression slope from cross-sectional data as a causal effect.

    InsteadDescribe slopes as associations unless the design supports causal inference.

  • MistakeUsing the line to predict far beyond the range of the data.

    InsteadRestrict predictions to the observed range of x; extrapolation assumes the pattern continues.

  • MistakeAssuming a correlation between group averages applies to individuals.

    InsteadAvoid the ecological fallacy; match the unit of analysis to the question.

Summary and key terms

  • Scatterplots show the direction, form and strength of a relationship and reveal outliers; always plot first.
  • Pearson’s r measures linear association from −1 to +1; Spearman’s rank correlation measures monotonic association and resists outliers.
  • Simple linear regression fits ŷ = b₀ + b₁x by least squares; the slope is the change in mean y per unit of x.
  • r² is the proportion of variation in y explained by x; the residual SD describes typical prediction error.
  • A t-test with n − 2 df tests whether the slope is zero; report the slope with its confidence interval.
  • Check the LINE assumptions with residual plots and investigate influential points.
  • Correlation is not causation; watch for confounding, reverse causation, ecological fallacy and restricted range.
Scatterplot
A graph showing one point per observation for two numerical variables.
Pearson correlation coefficient
A measure from −1 to +1 of the strength and direction of a linear relationship.
Spearman rank correlation
A correlation calculated on ranks, measuring monotonic association.
Slope
In regression, the change in the mean response for a one-unit increase in the predictor.
Intercept
The predicted value of the response when the predictor equals zero.
Residual
Observed value minus predicted value.
Least squares
The method that chooses the line minimizing the sum of squared residuals.
Coefficient of determination
r², the proportion of variation in the response explained by the model.
Extrapolation
Predicting outside the range of the data used to fit a model.
Ecological fallacy
Wrongly inferring individual-level relationships from group-level data.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. A regression of birth weight (g) on maternal weight gain (kg) gives ŷ = 2,900 + 18x. Interpret the slope and predict birth weight for a 15 kg gain.

    Show answer

    Mean birth weight is about 18 g higher for each additional kilogram of weight gain. Prediction: 2,900 + 18 × 15 = 3,170 g.

  2. The correlation between weekly hours of screen time and a fitness score is −0.40. What proportion of the variation in fitness is explained by screen time?

    Show answer

    r² = 0.16, so 16 percent.

  3. A residual plot shows residuals spreading out like a funnel as fitted values increase. Which assumption is violated and what might help?

    Show answer

    Equal variance (homoscedasticity). A log transformation of the outcome, or methods with robust standard errors, may help.

  4. Countries with more physicians per person have higher rates of diagnosed cancer. Give two reasons this does not show that physicians cause cancer.

    Show answer

    Confounding (wealthier countries have both more physicians and older populations), detection (more physicians find more cancers), and the ecological fallacy (country-level data say nothing about individuals).

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz