Chapter 16 · Making sense of numbers

Do two things move together?

Correlation coefficients, linear and logistic regression, multivariate analysis.

12 TNMGRMU questions answered hereset 19 times, 2009–2024

The problem first

You are an MD Medicine resident. In 200 patients with type 2 diabetes, serum vitamin D and HbA1c give r = −0.32, p < 0.001. Your discussion says that vitamin D deficiency causes poor glycaemic control and recommends supplements for every patient.

At the viva the examiner asks one question.

“How much of the variation in HbA1c does vitamin D explain, and how do you know it is a cause?”

Start here

Do two measurements move together?

Plot one measurement against the other, one dot per patient. The correlation coefficient, r, describes the pattern with one number between −1 and +1.

r = −1perfect negativer = −0.5moderate negativer = 0no straight-line relationr = 0.5moderate positiver = 1perfect positive
Each dot is one patient, and all five panels use the same scale. The closer the dots are to a straight line, the further r is from 0. The sign gives the direction: plus when both rise together, minus when one rises as the other falls. Data generated in Python with the exact r shown.

r = 0 means there is no straight-line relation. It does not rule out a curved one. For x from −5 to 5 and y = x², r is exactly 0, although y depends completely on x. Draw the scatter plot before you calculate r.

Two types of correlation

Pearson or Spearman: which coefficient do you need?

Pearson's r measures how close the points are to a straight line. Spearman's ρ (rho) first ranks each variable and then correlates the ranks, so it measures whether one variable consistently rises or falls as the other rises.

Curved, but always risingNo relation, one outlieroutlierPearson r = 0.85Spearman ρ = 1.00Pearson r = 0.75 (0.00 without the outlier)Spearman ρ = 0.37
Left: the rank order is perfect, so ρ = 1.00, but the points are not on a straight line, so r = 0.85. Right: eleven points with r = 0.00 and one extreme value. The single outlier raises Pearson's r to 0.75. Ranking limits its effect, and ρ = 0.37. Teaching data generated in Python.

r = Σ(x − x)(y − y) ÷ √[Σ(x − x)² × Σ(y − y)²]

ρ = 1 − 6Σd² ÷ [n(n² − 1)]

x, y
the means of x and y
Σ(x − x̄)(y − ȳ)
the sum of the products of the deviations from the means, the "product-moment" in the full name
d
the difference between each patient's rank on x and rank on y (the short formula is exact when there are no tied ranks)
n
the number of pairs

The numerator of r divided by n − 1 is the covariance, cov(x, y) = Σ(x − x)(y − y) ÷ (n − 1). Its sign gives the direction of the relation, but its size depends on the units: recording age in months instead of years multiplies it by 12. Dividing by the two SDs removes the units, so r = cov(x, y) ÷ (SD of x × SD of y). In the worked example below, cov = 1,200 ÷ 9 = 133.3 mmHg-years, the SD of age is 15.14 years and the SD of SBP is 10.69 mmHg, so r = 133.3 ÷ (15.14 × 10.69) = 0.82.

FeaturePearson's rSpearman's ρ
MeasuresCloseness to a straight lineConsistency of rank order (a monotonic relation)
DataTwo measurements on an interval or ratio scaleOrdinal scores, or measurements that are skewed or have outliers
AssumptionsStraight-line relation. For p values and confidence intervals, both variables roughly normalNo assumption about the distribution. The relation should go in one direction
OutliersStrongly affectedMuch less affected
ExampleAge and systolic blood pressurePain score and opioid dose

A third rank coefficient, Kendall's τ (tau), compares every pair of patients and counts how many are in the same order on both variables and how many are in the opposite order.

Interactive

Add or remove points and watch Pearson's r and Spearman's ρ change

Try this: with "No relation" chosen, tick "Add one outlier". Pearson's r rises from 0.00 to 0.75, but Spearman's ρ rises only from 0.18 to 0.37.

Teaching data on a scale of 0 to 10. Click an empty part of the plot to add a point. Click a point to remove it.

Starting data
00224466881010xy
0.00Pearson r
0.18Spearman ρ

11 points. Pearson's r is 0.00 and Spearman's ρ is 0.18, a difference of 0.18.

Interpreting r

What do r and r² tell you?

r gives the direction and closeness of a straight-line relation. r², the coefficient of determination, is the proportion of the variation in one variable that the straight line accounts for.

r = 0.3r² = 0.09r = 0.5r² = 0.25r = 0.7r² = 0.49r = 0.9r² = 0.8100.250.50.751
Grey bars: r. Red bars: r². r² is smaller than r for every value between 0 and 1. An r of 0.5 means the line accounts for 25% of the variation. In the opening case, r = −0.32 gives r² = 0.10, so vitamin D accounts for about 10% of the variation in HbA1c.

Is r statistically significant?

t = r × √(n − 2) ÷ √(1 − r²), with n − 2 degrees of freedom

The test asks whether r could be 0 in the population. It says nothing about strength. With r = 0.10, the p value is 0.49 in 50 patients and 0.0015 in 1,000 patients. In both cases the line accounts for 1% of the variation. In the opening case, r = −0.32 in 200 patients gives t = −4.75 and p < 0.001, which shows that r is unlikely to be 0, not that the relation is strong.

Report r with its 95% confidence interval and n. The SAMPL guidelines advise against calling a correlation low, moderate or high unless the ranges for those words have been defined.

When r misleads

  • The relation is curved: r underestimates it.
  • One or two outliers: r can be raised or lowered by a single patient.
  • A narrow range of values, for example only patients with normal blood pressure: r is lower than in the full population.
  • Repeated measurements from the same patients counted as separate pairs: the pairs are not independent.

Interactive

Draw samples and watch how r and its p value vary with sample size

Try this: set the true correlation to 0, choose 10 patients and press "Draw another sample" several times. Watch how far r moves from 0 between samples.

Teaching simulation: each dot is one simulated patient, drawn from a population in which the correlation is the value you set.

−0.30

A study sees only its sample, never this value

Patients in the sample

More patients → r is usually closer to the true value

True correlation in the population−0.30r in this sample of 200−0.28−1−0.500.51r from each sample drawn (latest in red)dashed line: true correlation
−0.28r in this sample
< 0.001p value (null hypothesis: correlation 0)

95% CI −0.40 to −0.15 · r² = 0.08 · t = −4.08 with 198 degrees of freedom

r² = 0.08, so a straight line accounts for 7.8% of the variation in this sample. The 95% confidence interval includes the true correlation of −0.30. p is below 0.05.

Correlation and cause

If two things correlate, does one cause the other?

Not necessarily. Before you call a correlation a cause, rule out chance, reverse causation, bias and confounding.

SmokingYellow-stainedfingersLung damagecorrelated,but no arrow between themlung damage scorefinger staining scorenon-smokerssmokersall 30: r = 0.86within each group: r = 0.00
Smoking causes both yellow-stained fingers and lung damage. Across all 30 people the two scores correlate closely (r = 0.86). Within smokers, and within non-smokers, r = 0.00. Smoking is a confounder: it is related to both variables and produces the correlation between them. Teaching data generated in Python.
  • Chance: test enough pairs of variables and some will correlate by chance alone.
  • Reverse causation: the outcome can change the exposure. Patients who are unwell go outdoors less and have lower vitamin D.
  • Confounding: a third factor affects both variables, as smoking does in the figure.
  • Selection bias: the way patients were chosen can create a correlation that does not exist in the population.
  • Regression toward the mean: patients chosen because a first reading was extreme will, on average, read closer to the mean the next time, even without treatment. A fall in blood pressure among patients recruited for a high first reading is partly this effect, which is one reason a control group is needed. It is the effect Galton described in 1886 (see History). It is covered with other misleading patterns in the Practical Statistics chapter on statistical fallacies.

A partial correlation is the correlation between two variables with a third held constant. For one variable z, rxy·z = (rxy − rxz × ryz) ÷ √[(1 − rxz²)(1 − ryz²)]. In the figure, holding smoking constant by looking within smokers and within non-smokers removes the correlation between the two scores. Adjusting for several variables at once is done with multiple regression, covered in the Practical Statistics chapter on multiple regression.

Designs that deal with these explanations are covered in the chapters on study designs and bias and validity. A randomised trial of vitamin D supplements, not a correlation, would show whether raising vitamin D lowers HbA1c.

Comparison

Correlation or regression: what is the difference?

Correlation describes how closely two variables vary together. Regression describes how much the outcome changes for each unit change in a predictor, and gives an equation to predict it.

FeatureCorrelationRegression
QuestionHow closely do x and y vary together?How much does y change when x rises by 1 unit?
Roles of the variablesSymmetrical: the r of x with y equals the r of y with xOne outcome (dependent variable, y) and one or more predictors (independent variables, x)
Resultr, from −1 to +1, with no unitsCoefficient b, in units of y per unit of x, and an intercept a
PredictionNot possiblePredicted y = a + bx
TypesPearson for measurements, Spearman for ranksLinear for measurements, logistic for yes/no, Cox for time to an event
ExampleAge and SBP: r = 0.82SBP rises 0.58 mmHg for each year of age
Shallow liner = 0.90 · b = 0.45Steep liner = 0.90 · b = 1.80
The same 20 points and the same r = 0.90 in both plots. Only the units of y differ, and the slope is 0.45 on the left and 1.80 on the right. r shows how close the points are to the line, not how steep the line is. The two are linked: b = r × SD of y ÷ SD of x.

The formula

How is the regression line calculated?

Simple linear regression fits the straight line that makes the sum of the squared vertical distances from the points to the line as small as possible. This is the method of least squares.

y = a + b × x

b = Σ(x − x)(y − y) ÷ Σ(x − x)²    a = y − b × x

y
the outcome (dependent variable)
x
the predictor (independent variable)
b
the regression coefficient, or slope: the change in y for a 1-unit rise in x
a
the intercept: the predicted y when x = 0
residual
observed y minus the y predicted by the line

Worked example (teaching data)

Age (years)30354045505560657075
SBP (mmHg)118130121135128142131150139148

mean age = 52.5   mean SBP = 134.2

Σ(x − x)(y − y) = 1,200.0   Σ(x − x)² = 2,062.5   Σ(y − y)² = 1,027.6

b = 1,200.0 ÷ 2,062.5 = 0.58 mmHg per year

a = 134.2 − 0.5818 × 52.5 = 103.65 mmHg

r = 1,200.0 ÷ √(2,062.5 × 1,027.6) = 0.82 → r² = 0.68

304050607080110120130140150Age (years)Systolic BP (mmHg)+10 years+5.8 mmHgSBP = 103.7 + 0.58 × ager = 0.82, r² = 0.68
Each dot is one adult. The dashed red lines are the residuals, and least squares makes the sum of their squares as small as possible. The line passes through the point (mean age, mean SBP), marked with a ring. Predicted SBP at 60 years: 103.65 + 0.582 × 60 = 138.6 mmHg.

b = 0.58 mmHg per year (95% CI 0.26 to 0.91, p = 0.003). The confidence interval does not include 0. The same calculation in Python:

from scipy import stats
age = [30, 35, 40, 45, 50, 55, 60, 65, 70, 75]
sbp = [118, 130, 121, 135, 128, 142, 131, 150, 139, 148]
fit = stats.linregress(age, sbp)
print(fit.slope, fit.intercept, fit.rvalue, fit.pvalue)
# slope 0.582, intercept 103.65, r 0.824, p 0.003

How well does the line fit?

SST = Σ(y − y)² = 1,027.6 (all the variation in SBP)

SSE = Σ(y − predicted y)² = 329.4 (left in the residuals)

SSR = SST − SSE = 698.2 (accounted for by the line)

R² = SSR ÷ SST = 698.2 ÷ 1,027.6 = 0.68, the same as r²

The residual SD, also called the standard error of the estimate, is s = √[SSE ÷ (n − 2)] = √(329.4 ÷ 8) = 6.42 mmHg. Observed SBP lies typically about 6 mmHg from the line, compared with an SD of 10.69 mmHg around the mean SBP.

SE of b = s ÷ √Σ(x − x)² = 6.42 ÷ √2,062.5 = 0.141

t = b ÷ SE of b = 0.582 ÷ 0.141 = 4.12, df 8, p = 0.003

This t is the same as the t for r (4.12 with 8 df), because in simple linear regression the test of b = 0 and the test of r = 0 are the same test. The 95% CI for b is 0.582 ± 2.306 × 0.141 = 0.26 to 0.91.

Assumptions to check

  • The relation is a straight line (look at the scatter plot).
  • Observations are independent: one row per patient.
  • The residuals have a similar spread at all values of x (plot residuals against predicted values).
  • The residuals are roughly normal, for confidence intervals and p values.
  • Predict only within the range studied. This line describes ages 30 to 75.

Interactive

Move the line and watch the sum of squared residuals

Try this: move the slope slider until the sum of squared residuals is as small as you can make it. Then tick "Show the least-squares line" to compare.

Teaching data from the worked example: age and systolic BP in 10 adults. The dashed red lines are the residuals.

0.00

Changing the slope rotates the line around the ring at the mean age

134.2 mmHg

The least-squares line passes through the mean SBP, 134.2 mmHg

304050607080110120130140150Age (years)Systolic BP (mmHg)
your line
1,027.6sum of squared residuals for your line (mmHg²)
329.4smallest possible sum, from the least-squares line

Your line: SBP = 134.20 + 0.00 × age · least squares: SBP = 103.65 + 0.58 × age

Your line accounts for 0.0% of the variation in SBP (1 − 1,027.6 ÷ 1,027.6). The least-squares line accounts for 67.9%, which is r².

Checking the model

How do residuals show whether a straight line is the right model?

A residual is the observed value minus the value predicted by the line. Plot the residuals against the predicted values. If the model is right, they form a band of even width around 0, with no pattern.

Worked exampleresidual0predicted valueno patternCurved relationresidual0predicted valueU-shaped patternSpread growsresidual0predicted valuefunnel shape
Left: the ten residuals from the worked example (−7.6 to +8.5 mmHg), scattered around 0 without a pattern. Middle: made-up data that follow a curve, fitted with a straight line. The residuals are positive at both ends and negative in the middle, so the line misses the curve even though r = 0.70. Right: made-up data whose spread grows with the predicted value, a funnel shape. The line may be the right shape, but its SE, confidence intervals and p-values are not reliable.
What the residual plot showsWhat it suggestsWhat to do
A curve (U or inverted U)The relation is not a straight lineAdd a squared term, transform x or y, or fit a different model
A funnel: spread grows with the predicted valueThe variance is not constantTry a transformation of y, such as a logarithm, with a statistician's help
A few residuals much larger than the restOutliers: data-entry errors, or patients unlike the othersCheck the records. Report the analysis with and without them
A pattern in the order of measurementThe residuals are not independent, for example repeated readings over timeUse methods for repeated or time-ordered data
A skewed histogram of residualsThe residuals are not roughly normalConfidence intervals and p-values may be inaccurate in small samples

A high r or R² does not show that the model is right. The curved data in the middle panel have r = 0.70, yet a straight line is the wrong shape for them. The SAMPL guidelines ask authors to state whether an analysis of residuals confirmed the assumptions of linearity (see Guidelines).

Prediction

How precise is a prediction, and why not predict beyond the data?

A regression line gives two different intervals. The confidence interval shows where the mean outcome lies for patients with a given x. The prediction interval shows where one new patient's value is likely to lie, and it is always wider.

95% CI for the mean at x₀ = ŷ ± t × s × √[1/n + (x₀ − x)² ÷ Sxx]

95% prediction interval = ŷ ± t × s × √[1 + 1/n + (x₀ − x)² ÷ Sxx]

ŷ
the value predicted by the line at x₀
t
from the t distribution with n − 2 df: 2.306 for 8 df
s
the residual SD, 6.42 mmHg in the worked example
Sxx
Σ(x − x)², 2,062.5 in the worked example

Worked example at age 60: ŷ = 138.6 mmHg. The 95% CI for the mean SBP of 60-year-olds is 133.3 to 143.8 mmHg. The 95% prediction interval for one 60-year-old is 122.9 to 154.3 mmHg. Because of the term (x₀ − x)², both intervals widen as x₀ moves away from the mean age of 52.5.

Extrapolation. The ten adults were 30 to 75 years old. At 90 years the formula gives 156.0 mmHg (95% CI 142.9 to 169.1), but that calculation assumes the straight line continues beyond 75, and the data cannot show whether it does. Predict only within the range of x that was studied.

The intercept. a = 103.65 mmHg is the predicted SBP at age 0. No one near age 0 was studied, so here the intercept only fixes the position of the line and has no clinical meaning.

Interactive

Move the age and watch the confidence and prediction intervals widen

Both intervals are narrowest at the mean age. Beyond the ages studied they keep widening, and they also rest on an assumption the data cannot check.

Try this: move the age to 52.5, the mean age. Both intervals are at their narrowest there: ±4.7 mmHg for the mean and ±15.5 mmHg for one adult. Then move to 90. The line still gives a value, but 90 is outside the ages studied, and the interval for the mean has widened to ±13.1 mmHg.

Teaching data from this chapter: 10 adults aged 30 to 75, SBP = 103.65 + 0.582 × age, residual SD 6.42 mmHg, t with 8 df.

60.0 years

The ages studied were 30 to 75

138.6predicted SBP, mmHg
133.3 to 143.895% CI for the mean SBP at this age
122.9 to 154.395% prediction interval for one adult

Age 60.0 is within the ages studied. The interval for one adult (±15.7 mmHg) is wider than the interval for the mean (±5.3 mmHg), because individual adults vary around the line.

not studiednot studied2030405060708090100100120140160180Age (years)
95% CI for the mean (darker band), prediction interval (lighter band)line beyond the ages studiedthe age you chose

More than one predictor

What if several factors affect the outcome?

Multiple linear regression puts several predictors in one equation. Each coefficient is then the change in the outcome for a 1-unit change in that predictor, with the other predictors held constant.

y = a + b₁x₁ + b₂x₂ + … + bₖxₖ

SBP = 57.8 + 0.52 × age + 1.90 × BMI   (R² = 0.94)

Teaching example: the same 10 adults with BMI added, fitted in Python (statsmodels). Age alone gave 0.58 mmHg per year. Adjusted for BMI, the coefficient for age is 0.52 mmHg per year (95% CI 0.37 to 0.68), and each extra kg/m² of BMI adds 1.90 mmHg (95% CI 1.10 to 2.71). A 60-year-old with a BMI of 25 has a predicted SBP of 136.8 mmHg.

  • Uses: adjusting for confounders, predicting an outcome from several factors, and finding which factors are associated with the outcome independently of the others.
  • Multicollinearity: when predictors are strongly correlated with each other, their coefficients become unstable. How to detect it and what to do is in the Practical Statistics chapter on multicollinearity.
  • Overfitting: too many predictors for the number of patients fit chance patterns that do not repeat in new patients.
  • R² always rises when a predictor is added. Adjusted R² (0.92 here) allows for the number of predictors.
  • Multiple R is the correlation between the observed outcome and the value predicted by the model. Its square is R². With one predictor, R equals the size of r without its sign.
  • Choose predictors from clinical knowledge before the analysis, and report how they were selected. Building and checking models with several predictors is covered in the Practical Statistics chapter on multiple regression.

Yes-or-no outcomes

What if the outcome is yes or no?

A straight line can predict probabilities below 0 or above 1. Logistic regression models the log of the odds instead, so the predicted probability follows an S-shaped curve that stays between 0 and 1.

00.510246810Risk scoreProbability of the outcomeodds 0.5odds 1odds 2odds 4each 1-point risedoubles the odds: OR = 2
Teaching model: log odds = −3.47 + 0.693 × score. The coefficient 0.693 is the natural log of 2, so each 1-point rise in the score doubles the odds. The probability rises by different amounts at different parts of the curve, but the odds ratio stays at 2.

ln[p ÷ (1 − p)] = a + b₁x₁ + b₂x₂ + … + bₖxₖ

odds ratio for a 1-unit rise in x = eb   95% CI = e(b ± 1.96 × SE)

p
probability of the outcome
p ÷ (1 − p)
the odds of the outcome
ln
natural logarithm: ln(odds) is the logit
e^b
the odds ratio for that predictor, adjusted for the others in the model

Worked example (teaching data)

Wound infection after surgery: 20 of 100 patients with diabetes and 20 of 200 patients without diabetes.

odds with diabetes = 20 ÷ 80 = 0.25   odds without = 20 ÷ 180 = 0.111

OR = 0.25 ÷ 0.111 = 2.25 → b = ln 2.25 = 0.811

A logistic regression with diabetes (1 = yes, 0 = no) as the only predictor gives the same result: intercept −2.197, coefficient 0.811, OR 2.25 (95% CI 1.15 to 4.41). If age and BMI are added to the model, the OR for diabetes becomes an adjusted odds ratio, which compares patients of the same age and BMI.

How many predictors can the model take?

Peduzzi and colleagues (1996) simulated logistic models and found that with fewer than 10 events per predictor variable the coefficients were biased in both directions and the confidence intervals did not have the correct coverage. With 10 or more events per variable, no major problems occurred. Vittinghoff and McCulloch (2007) found situations in which fewer than 10 events per variable gave acceptable results and concluded that the rule can be relaxed. Count events, not patients. Logistic regression is covered in more depth in the Practical Statistics chapter on logistic regression.

Time-to-event outcomes

What if the outcome is time until an event?

Cox regression models the hazard, the rate at which the event occurs at each point in time, from one or more predictors. Patients whose event has not happened by the end of follow-up (censored patients) still contribute.

hazard ratio for a 1-unit rise in x = eb

D.R. Cox described the model in 1972. It assumes that the hazard ratio between groups stays the same over time (proportional hazards). A hazard ratio of 0.70 for a drug means that, at any time during follow-up, treated patients have the event at 70% of the rate of untreated patients. Survival curves, censoring and hazard ratios are covered in the risk and survival chapter.

Multivariate or multivariable

What does multivariate analysis mean?

Strictly, multivariate analysis models two or more outcome variables at the same time. A model with one outcome and several predictors is multivariable. The two words are often used as if they meant the same thing.

FeatureMultivariableMultivariate
Outcome variablesOneTwo or more, modelled together
PredictorsSeveralOne or more
ExamplesMultiple linear, logistic or Cox regression with several predictorsThe same outcome measured repeatedly on each patient, clustered data, MANOVA
Typical useAdjusting for confounders, prediction modelsOutcomes that are correlated with each other

Hidalgo and Goodman reviewed one year of the American Journal of Public Health (December 2010 to November 2011). Of 30 articles that described a “multivariate” method, 25 (83%) had used multivariable analyses. They recommend describing a model as simple or multivariable for the number of predictors, and as linear, logistic, multivariate or proportional hazards for the type of outcome.

In textbooks and exam questions, “multivariate analysis” is also used as a broad heading for methods that handle many variables at once: multiple regression, MANOVA, principal component analysis, factor analysis, cluster analysis and discriminant analysis.

Ph.D. question

What is partial least squares regression?

Partial least squares (PLS) regression predicts an outcome from many predictors that are strongly correlated with each other, including data sets with more predictors than subjects. Ordinary least squares regression gives unreliable coefficients in the first situation and cannot be used in the second.

8 correlated measurementsmeasurement 1measurement 2measurement 3measurement 4measurement 5measurement 6measurement 7measurement 8Component1Component2Outcome ychosen to predict yPCA would build components from the measurements alone, without using y.
PLS combines the predictors into a few new variables called components (latent variables). Each component is a weighted combination of the original predictors. The weights are chosen using the outcome, so the components predict it well. The outcome is then regressed on these few components.
FeaturePrincipal component regressionPLS regression
Components built fromThe predictors onlyThe predictors and the outcome
First componentCaptures the largest share of the variation in the predictorsChosen to predict the outcome
ResultComponents may not relate closely to the outcomeComponents correlate more closely with the outcome
  • When to use it: many correlated measurements, such as spectra, imaging data or large laboratory panels, often with few subjects.
  • How it is checked: by cross-validation, which tests the predictions on data not used to fit the model.
  • Origin: first proposed by Herman Wold in the 1960s, and widely used in chemistry (chemometrics) from the 1980s.
  • Limitation: the components are combinations of many predictors, so the model predicts well but is harder to interpret one variable at a time.

In clinical studies

What do correlation and regression coefficients do in a clinical study?

Each coefficient answers a different question. The one you report decides what you can claim.

CoefficientWhat it tells youExample in this chapter
Pearson rDirection and closeness of a straight-line relationAge and SBP, r = 0.82
Spearman ρConsistency of rank orderPain score and opioid dose
r²Share of variation accounted for by the liner = −0.32 → about 10%
b, linear regressionChange in the outcome per unit of the predictorSBP +0.58 mmHg per year of age
Adjusted bThe same, with other predictors held constant+0.52 mmHg per year, adjusted for BMI
OR = eb, logisticMultiplies the odds of a yes/no outcomeDiabetes and wound infection, OR 2.25
HR = eb, CoxMultiplies the hazard of an eventHR 0.70: event rate 70% of the comparison group
  • Describing an association and generating hypotheses: r or ρ with a confidence interval.
  • Controlling confounding in observational studies: adjusted coefficients, reported with the unadjusted ones (STROBE item 16a).
  • Adjusting for baseline covariates in trials, planned in the protocol (ICH E9).
  • Prediction: risk scores. In 1967 Truett, Cornfield and Kannel published the first multivariable risk function for coronary heart disease from the Framingham study.
  • Calibration in the laboratory: a regression line of instrument reading on known concentrations converts a patient's reading into a concentration.

Decide

Which method fits your question?

Answer two or three questions. Each answer links to the section that explains it.

What do you want to know?

Which method: all possible answers
  • Pearson correlation coefficient (r): Report r with its 95% confidence interval and n. r² is the share of the variation explained by the straight line.
  • Spearman rank correlation (ρ): Rank each variable, then correlate the ranks. Use it for ordinal scores, skewed data, curved but one-directional patterns, or outliers.
  • Bland–Altman analysis, not correlation: Two methods can correlate closely and still give different values. Plot the difference between the methods against their mean.
  • Simple linear regression: y = a + bx. b is the change in the outcome for each 1-unit change in x.
  • Multiple linear regression: Each coefficient is adjusted for the other predictors. Choose the predictors before you look at the data.
  • Partial least squares regression: Builds a few components from the predictors, chosen to predict the outcome. Check the model by cross-validation.
  • Logistic regression: Each coefficient converts to an odds ratio, OR = exp(b). Count the events per predictor variable before adding predictors.
  • Cox regression: Each coefficient converts to a hazard ratio. Censored patients (event not yet seen) still contribute.
  • Multivariate analysis: Models two or more outcome variables together, for example repeated measurements on the same patients. Involve a statistician.

By specialty

Correlation and regression problems by specialty

HbA1c is higher in patients with a longer duration of diabetes, but those patients are also older.

Put duration and age in one multiple regression model and report both the crude and the adjusted coefficient for duration.

Common myths

Common mistaken beliefs

  • Myth: r = 0 means the two variables are unrelated.

    r = 0 means there is no straight-line relation. A U-shaped relation can give r = 0 exactly.

  • Myth: A strong correlation proves cause and effect.

    Chance, reverse causation, bias and confounding can all produce a correlation. A causal claim needs a design that deals with them.

  • Myth: A high correlation between two methods of measurement means they agree.

    Bland and Altman (1986) showed that correlation coefficients are misleading for this purpose. Two methods can correlate closely while one always reads higher. Plot the differences against the means. Methods for agreement are covered in the Practical Statistics chapter on ICC and Bland–Altman analysis.

  • Myth: A small p value means a strong correlation.

    The p value depends on sample size. In 1,000 patients, r = 0.10 has p = 0.0015 and accounts for 1% of the variation.

  • Myth: The regression of y on x can be turned around to predict x from y.

    In the worked example, SBP on age gives 0.58 mmHg per year. Age on SBP gives 1.17 years per mmHg, not 1 ÷ 0.58 = 1.72. The two lines coincide only when r is +1 or −1.

  • Myth: "Multivariate" means a model with many predictors.

    That is a multivariable model. Multivariate means two or more outcome variables. In one year of a public health journal, 25 of 30 articles that said "multivariate" had used multivariable models (Hidalgo and Goodman, 2013).

Why this matters to you

Five consequences of misusing correlation and regression

  1. Protocol sent back

    The analysis plan says "correlation and multivariate analysis" without naming the coefficient, the outcome or the predictors.

  2. A causal claim the thesis cannot support

    A cross-sectional correlation written up as "vitamin D deficiency causes poor glycaemic control".

  3. Viva questions on r²

    Unable to explain that r = −0.32 accounts for about 10% of the variation in the outcome.

  4. Misreading papers

    Quoting an unadjusted odds ratio as the effect of an exposure, or accepting a logistic model with 12 predictors and 30 events.

  5. Treatment that does not help patients

    Supplements prescribed on the basis of a correlation may not change the outcome at all.

History

History of correlation and regression

  1. 1886

    Francis Galton

    Published “Regression towards mediocrity in hereditary stature”. Children of unusually tall or short parents were, on average, closer to the population average. He reported that the children's deviations were to those of their mid-parents “as 2 to 3”.

  2. 1888

    Francis Galton

    In “Co-relations and their measurement, chiefly from anthropometric data”, defined co-relation between two measurements and showed that its closeness could be expressed by a single number.

  3. 1896

    Karl Pearson

    Published a mathematical treatment of correlation and regression in the Philosophical Transactions of the Royal Society, calculating both from the product-moment. The letter r, which Galton had used for the slope of the regression line, came to stand for the correlation coefficient.

  4. 1904

    Charles Spearman

    “The proof and measurement of association between two things” included comparison by rank, the basis of rank correlation.

  5. 1958

    D.R. Cox

    “The regression analysis of binary sequences” dealt with outcomes recorded as 0 or 1 whose probability depends on one or more independent variables.

  6. 1967

    Truett, Cornfield and Kannel

    Published the first multivariable risk function for coronary heart disease from the Framingham study.

  7. 1972

    D.R. Cox

    “Regression models and life-tables” modelled the hazard as a function of explanatory variables and regression coefficients, multiplied by an unspecified function of time.

  8. 1986

    J. Martin Bland and Douglas Altman

    Showed that correlation coefficients are misleading when two methods of clinical measurement are compared, and described a graphical alternative.

  9. 1996

    Peduzzi and colleagues

    In a simulation study, logistic regression coefficients were biased when there were fewer than 10 events per predictor variable.

  10. 2007

    Vittinghoff and McCulloch

    Found situations in which fewer than 10 events per variable gave acceptable results, and concluded that the rule can be relaxed.

Guidelines

Correlation and regression in reporting guidelines

SAMPL guidelines (Lang and Altman), correlation

“Identify the correlation coefficient used in the analysis (e.g., Pearson, Spearman).” “Do not describe correlation as low, moderate, or high unless the ranges for these categories have been defined.” For primary comparisons, report the 95% confidence interval for the correlation coefficient “whether or not it is statistically significant”.

SAMPL guidelines (Lang and Altman), regression

“For either simple or multiple (multivariable) regression analyses, report the regression equation.” For multiple regression, report “whether the variables were assessed for a) colinearity and b) interaction” and describe the variable selection process. In linear regression, indicate “whether an analysis of residuals confirmed the assumptions of linearity”.

STROBE (2007), item 12(a)

“Describe all statistical methods, including those used to control for confounding.”

STROBE (2007), item 16(a)

“Give unadjusted estimates and, if applicable, confounder-adjusted estimates and their precision (e.g., 95% confidence intervals). Make clear which confounders were adjusted for and why they were included.”

ICH E9 (1998), section 5.7

Adjustment for covariates that is part of the planned analysis “should be set out in the protocol”. “It is not advisable to adjust the main analyses for covariates measured after randomisation because they may be affected by the treatments.”

Reading a paper

Five checks on any correlation or regression analysis

  • Is there a scatter plot, and does the pattern suit the coefficient used (Pearson for a straight line, Spearman for ranks, skew or outliers)?
  • Are r or ρ, its 95% confidence interval and n all reported, not only the p value?
  • Does an observational study claim cause from a correlation?
  • For adjusted estimates, are the confounders named with the reason for including each, and are the unadjusted estimates shown too?
  • For logistic or Cox models, how many events were there per predictor variable, and were the model assumptions checked?

Why is it called that?

Word surgery

“Regression”

In everyday speech

Going backwards, a relapse to an earlier state.

In research

A method that describes how an outcome changes with one or more predictors, and predicts the outcome.

“Correlation”

In everyday speech

Any connection between two things.

In research

A number from −1 to +1 for how closely two variables vary together, along a straight line (Pearson) or in rank order (Spearman).

“Multivariate”

In everyday speech

Involving many variables.

In research

Strictly, a model with two or more outcome variables. A model with one outcome and several predictors is multivariable.

Memory trick

r: how close the points are to the line. b: how steep the line is. r²: the share of the variation that the line accounts for.

Regression

Latin regressio: "a going back, a return"

Galton (1886) found that children of unusually tall or short parents were, on average, closer to the population average, and called this "regression towards mediocrity". The name stayed with the method.

Correlation

Galton (1888) wrote it "co-relation"

Two measurements related to each other, so that when one varies the other tends to vary as well.

Coefficient

co- + efficient: "that which unites in action with something else to produce a given effect"

A number that multiplies a variable in an equation. In y = a + bx, b is the regression coefficient.

Product-moment

"moment" here means the mean of a set of products

Pearson's r is calculated from the products of each patient's deviations from the two means.

Residual

Latin residuum: "that which is left behind"

The part of each patient's value that the line does not account for: observed value minus predicted value.

Confounding

Latin confundere: "to pour, mingle, or mix together"

The effect of a third factor is mixed in with the effect you are studying.

r

Galton used r for the slope of his regression line

After Pearson's 1896 paper, r came to stand for the correlation coefficient.

Exam answers

Model answer outlines

Correlation coefficient: the Pearson product-moment coefficient and its significance

MD Nuclear Medicine 2018, 2022 · DM Neonatology 2022 · MD Biochemistry 2017 · MD Community Medicine 2017 · Ph.D. RM 2014
  1. Definition: a measure of the direction and closeness of the straight-line relation between two quantitative variables. Range −1 to +1, no units.
  2. Formula: r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² × Σ(y − ȳ)²]. “Product-moment” refers to the mean of the products of the deviations from the means.
  3. Covariance: cov(x, y) = Σ(x − x̄)(y − ȳ) ÷ (n − 1) gives the direction but depends on the units. r = cov(x, y) ÷ (SD of x × SD of y) has no units. Worked example: 133.3 ÷ (15.14 × 10.69) = 0.82.
  4. Scatter diagram: draw it first. r = +1 or −1, all points on a line. r = 0, no straight-line relation.
  5. Interpretation: the sign gives the direction and the size gives the closeness. r² (coefficient of determination) is the proportion of variation explained, so r = 0.5 explains 25%.
  6. Assumptions: two quantitative variables, a straight-line relation, independent pairs, no extreme outliers, and roughly normal distributions for tests and confidence intervals.
  7. Significance: H₀ is that the population correlation is 0. t = r√(n − 2) ÷ √(1 − r²) with n − 2 degrees of freedom. The p value depends on n, so also give the 95% CI using Fisher's z = ½ ln[(1 + r) ÷ (1 − r)], SE = 1 ÷ √(n − 3).
  8. Worked example (teaching data): age and SBP in 10 adults, r = 0.82, t = 4.12, p = 0.003, 95% CI 0.41 to 0.96, r² = 0.68.
  9. Partial correlation: the correlation between two variables with a third held constant, rxy·z = (rxy − rxz × ryz) ÷ √[(1 − rxz²)(1 − ryz²)].
  10. Limitations: does not show cause, does not show agreement between two methods (use Bland–Altman), misses curved relations, and is distorted by outliers and a narrow range of values.

Two methods of correlation commonly used in research

MD Biochemistry 2024
FeaturePearson product-moment (r)Spearman rank (ρ)
TypeParametricNon-parametric
UsesActual valuesRanks of the values
FormulaΣ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² × Σ(y − ȳ)²]1 − 6Σd² ÷ [n(n² − 1)], d = difference in ranks
Relation measuredStraight lineConsistently rising or falling (monotonic)
DataBoth quantitative, roughly normalOrdinal scores, skewed data, outliers
ExampleAge and SBPPain score and opioid dose

In the worked example both give 0.82. With a curved relation or an outlier they differ (r 0.85 and ρ 1.00 for a curve). Kendall's τ is a third, rank-based coefficient.

Correlation coefficient and coefficient of variation

MD Biochemistry 2009
FeatureCorrelation coefficient (r)Coefficient of variation (CV)
DescribesRelation between two variablesSpread of one variable relative to its mean
FormulaΣ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² × Σ(y − ȳ)²]CV = SD ÷ mean × 100
Range and units−1 to +1, no unitsA percentage, no units
UseStrength and direction of associationComparing variability of measurements on different scales, and precision of laboratory assays
ExampleAge and SBP, r = 0.82Hb mean 12 g/dL, SD 1.5 g/dL → CV 12.5%

Both are free of units. The CV is covered in the descriptive statistics chapter.

Correlation and regression in clinical studies, and the role of their coefficients

Ph.D. RM 2015, 2017 · MD Community Medicine 2009
  • Correlation measures how closely two variables vary together (r or ρ). Regression describes how an outcome changes with predictors and predicts it (y = a + bx).
  • Differences: correlation is symmetrical and has no units. Regression has an outcome and predictors, and b has units (see the comparison table).
  • Role of r: direction and closeness of the relation. r² gives the proportion of variation explained. Example: age and SBP, r = 0.82, r² = 0.68.
  • Role of b: change in outcome per unit of predictor, used for prediction. Example: SBP rises 0.58 mmHg per year, predicted SBP at 60 years = 138.6 mmHg.
  • Adjusted coefficients: control confounding. Age coefficient 0.52 after adding BMI. STROBE item 16(a) asks for unadjusted and adjusted estimates.
  • Other outcomes: logistic regression gives odds ratios (diabetes and wound infection, OR 2.25). Cox regression gives hazard ratios.
  • Clinical uses: risk scores (Framingham multivariable risk function, 1967), baseline adjustment in trials (ICH E9), laboratory calibration lines.
  • Cautions: correlation is not cause, correlation is not agreement, do not predict beyond the range of the data, and check the assumptions.

Regression analysis

MD Biochemistry 2016, 2023 · DM Neonatology 2020 · MD Nuclear Medicine 2021
  1. Definition: a method that describes the relation between an outcome (dependent variable) and one or more predictors (independent variables), and predicts the outcome.
  2. Types by outcome: linear (measurement), logistic (yes/no), Cox (time to event), Poisson (counts). By number of predictors: simple (one) or multiple/multivariable (several). PLS regression for many correlated predictors.
  3. Simple linear regression: y = a + bx, fitted by least squares. b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², a = ȳ − b x̄.
  4. Worked example (teaching data): SBP = 103.65 + 0.58 × age, b 95% CI 0.26 to 0.91, r² = 0.68.
  5. Assumptions: straight-line relation, independent observations, residuals with constant spread and roughly normal distribution.
  6. Goodness of fit: SST = SSR + SSE, and R² = SSR ÷ SST (698.2 ÷ 1,027.6 = 0.68 in the example). Residual SD s = √[SSE ÷ (n − 2)] = 6.42 mmHg. Test of the slope: t = b ÷ SE of b = 0.582 ÷ 0.141 = 4.12, df 8.
  7. Residual plots: residuals against predicted values should form an even band around 0. A curve means the straight line is the wrong shape. A funnel means the variance is not constant.
  8. Prediction: the 95% CI for the mean outcome is narrower than the 95% prediction interval for one patient (age 60: 133.3 to 143.8 against 122.9 to 154.3 mmHg). Both widen away from the mean of x. Do not predict beyond the range of x studied.
  9. Multiple regression: each b is adjusted for the other predictors. Watch for multicollinearity and overfitting.
  10. Uses: prediction, adjustment for confounding, risk scores, laboratory calibration.
  11. Reporting (SAMPL): the regression equation, the coefficients with confidence intervals, and how assumptions, outliers and missing data were handled.
  12. Pitfalls: extrapolation beyond the data, causal claims from observational data, regression towards the mean.

Logistic regression

DM Neurology 2009
  1. Definition: regression for a binary outcome, such as good or poor outcome after stroke, with one or more predictors.
  2. Why not linear regression: a straight line can predict probabilities below 0 or above 1.
  3. Model: ln[p ÷ (1 − p)] = a + b₁x₁ + … + bₖxₖ. The left side is the logit (log odds).
  4. Coefficients: OR = eb for a 1-unit rise in the predictor, 95% CI = e(b ± 1.96 SE). With several predictors, each OR is adjusted for the others.
  5. Worked example (teaching data): wound infection in 20/100 with diabetes and 20/200 without. OR = 2.25, b = 0.811, 95% CI 1.15 to 4.41.
  6. Types: binary, multinomial (unordered categories), ordinal (ordered categories).
  7. Requirements: independent observations, a straight-line relation between continuous predictors and the log odds, no severe multicollinearity, and enough events per predictor. Peduzzi et al. (1996) found bias below 10 events per variable, and Vittinghoff and McCulloch (2007) showed the rule can be relaxed in some situations.
  8. Model checking: discrimination (C statistic, area under the ROC curve) and calibration (for example the Hosmer–Lemeshow test).
  9. Uses: identifying independent risk factors, adjusted odds ratios in case-control studies, prediction scores.

Multivariate analysis, and partial least squares regression

Ph.D. RM 2013, 2014, 2022

(a) Multivariate analysis

  • Strict meaning: analysis of two or more outcome variables together, such as repeated measurements on the same patient or clustered data.
  • Broad textbook meaning: methods that analyse many variables at once, including multiple regression, MANOVA, principal component analysis, factor analysis, cluster analysis and discriminant analysis.
  • A model with one outcome and several predictors is multivariable (Hidalgo and Goodman, 2013).
  • Uses: adjusting for confounding, reducing many correlated variables to a few, grouping patients, prediction.
  • Needs: an adequate sample size for the number of variables, and checks of the assumptions of each method.

(b) Partial least squares (PLS) regression

  1. Problem: many predictors that are highly correlated, or more predictors than subjects. Least squares estimates are unreliable or impossible.
  2. Idea: build a few components (latent variables), each a weighted combination of the predictors, with weights chosen so the components predict the outcome.
  3. Steps: extract the first component from the predictors using the outcome, regress the outcome on it, then extract further components that are uncorrelated (orthogonal) with the earlier ones.
  4. Checking: prediction quality is assessed by cross-validation, such as the bootstrap or jackknife.
  5. Compared with principal component regression: PCA builds components from the predictors only. PLS also uses the outcome, so its components correlate more closely with it.
  6. Uses: spectra in chemistry (chemometrics), brain imaging, large laboratory or “omics” panels.
  7. Origin: proposed by Herman Wold in the 1960s.
  8. Limitation: components are hard to interpret one variable at a time. The model is for prediction more than explanation.

(c) Meta-analysis, covered in the systematic review and meta-analysis chapter

  • Definition: statistical combination of the results of several studies of the same question, usually within a systematic review.
  • Steps: question and protocol, comprehensive search, study selection, data extraction, risk-of-bias assessment, pooling, heterogeneity assessment, publication bias assessment, reporting to PRISMA 2020.
  • Methods: inverse-variance weighting, fixed-effect or random-effects models, forest plot, I² for heterogeneity, funnel plot.
  • Assumptions: the studies address a similar question and outcome, and are independent. A fixed-effect model assumes one true effect. A random-effects model assumes the true effects vary around an average.

The one thing to remember

A correlation shows that two measurements vary together. It does not show that one causes the other.

The opening case, the scatter plots and the worked examples use made-up numbers for teaching. Every number was calculated in Python (numpy, scipy, statsmodels).

Sources: Galton F. J Anthropol Inst 1886;15:246 (doi:10.2307/2841583). Galton F. Proc R Soc Lond 1888;45:135–45 (doi:10.1098/rspl.1888.0082). Pearson K. Phil Trans R Soc Lond A 1896;187:253–318 (doi:10.1098/rsta.1896.0007). Stanton JM. J Stat Educ 2001;9(3) (doi:10.1080/10691898.2001.11910537). Spearman C. Am J Psychol 1904;15:72 (doi:10.2307/1412159), reprinted in Int J Epidemiol 2010;39:1137–50 (PMID 21051364). Cox DR. J R Stat Soc B 1958;20:215–32 (doi:10.1111/j.2517-6161.1958.tb00292.x). Truett J, Cornfield J, Kannel W. J Chronic Dis 1967;20:511–24 (PMID 6028270). Mahmood S et al. Lancet 2014;383:999–1008 (PMID 24084292). Cox DR. J R Stat Soc B 1972;34:187–202 (doi:10.1111/j.2517-6161.1972.tb00899.x). Bland JM, Altman DG. Lancet 1986;1:307–10 (PMID 2868172). Peduzzi P et al. J Clin Epidemiol 1996;49:1373–9 (PMID 8970487). Vittinghoff E, McCulloch CE. Am J Epidemiol 2007;165:710–8 (PMID 17182981). Hidalgo B, Goodman M. Am J Public Health 2013;103:39–40 (PMID 23153131). Liu C et al. Gen Psychiatr 2022;35:e100662 (PMID 35146334). Abdi H. WIREs Comput Stat 2010;2:97–106 (doi:10.1002/wics.51). Brereton RG. J Chemom 2025;39(12) (doi:10.1002/cem.70069). Lang TA, Altman DG. SAMPL guidelines. Int J Nurs Stud 2015;52:5–9 (PMID 25441757). von Elm E et al. STROBE statement. Lancet 2007;370:1453–7 (PMID 18064739). Vandenbroucke JP et al. STROBE explanation and elaboration. PLoS Med 2007;4:e297 (PMID 17941715). ICH E9 Statistical Principles for Clinical Trials, 1998. Page MJ et al. PRISMA 2020 statement. BMJ 2021;372:n71 (PMID 33782057).

Past papers

Every TNMGRMU question on correlation and regression

Each one is answered in this chapter. Tap a sitting to open the university's own question paper.

  1. ×4Regression analysisMD Biochemistry · Oct 2023MD Nuclear Medicine · Jul 2021DM Neonatology · Feb 2020MD Biochemistry · Apr 2016
  2. ×4Correlation coefficientMD Nuclear Medicine · May 2022MD Nuclear Medicine · May 2018MD Community Medicine · May 2017Ph.D. RM · Jul 2014
  3. ×2Multivariate analysisPh.D. RM · Jul 2022Ph.D. RM · Jul 2014
  4. ×1Write two methods of correlation commonly used in research methodologyMD Biochemistry · May 2024
  5. ×1Correlation coefficient and Pearson product-moment correlation coefficientDM Neonatology · Feb 2022
  6. ×1What is correlation coefficient? What is its significance?MD Biochemistry · May 2017
  7. ×1Explain regression and correlation in clinical studies with appropriate examplesPh.D. RM · Jul 2017
  8. ×1Correlation and RegressionPh.D. RM · Jul 2015
  9. ×1(a) Explain what is meant by ‘Multivariate Analysis’. (b) Explain in detail Partial Least Square Regression. (c) Explain what is Meta Analysis, the steps of Meta Analysis, the methods and assumptions of Meta AnalysisPh.D. RM · Jul 2013
  10. ×1Correlation coefficient and coefficient of variationMD Biochemistry · Sep 2009
  11. ×1What is the role of correlation and regression coefficient in statistical analysis?MD Community Medicine · Sep 2009
  12. ×1Logistic regressionDM Neurology · Aug 2009

Further reading

Related Stateazy articles