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 = 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.
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.
| Feature | Pearson's r | Spearman's ρ |
|---|---|---|
| Measures | Closeness to a straight line | Consistency of rank order (a monotonic relation) |
| Data | Two measurements on an interval or ratio scale | Ordinal scores, or measurements that are skewed or have outliers |
| Assumptions | Straight-line relation. For p values and confidence intervals, both variables roughly normal | No assumption about the distribution. The relation should go in one direction |
| Outliers | Strongly affected | Much less affected |
| Example | Age and systolic blood pressure | Pain 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.
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.
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.
A study sees only its sample, never this value
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.
- 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.
| Feature | Correlation | Regression |
|---|---|---|
| Question | How closely do x and y vary together? | How much does y change when x rises by 1 unit? |
| Roles of the variables | Symmetrical: the r of x with y equals the r of y with x | One outcome (dependent variable, y) and one or more predictors (independent variables, x) |
| Result | r, from −1 to +1, with no units | Coefficient b, in units of y per unit of x, and an intercept a |
| Prediction | Not possible | Predicted y = a + bx |
| Types | Pearson for measurements, Spearman for ranks | Linear for measurements, logistic for yes/no, Cox for time to an event |
| Example | Age and SBP: r = 0.82 | SBP rises 0.58 mmHg for each year of age |
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) | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 |
|---|---|---|---|---|---|---|---|---|---|---|
| SBP (mmHg) | 118 | 130 | 121 | 135 | 128 | 142 | 131 | 150 | 139 | 148 |
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
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.
Changing the slope rotates the line around the ring at the mean age
The least-squares line passes through the mean SBP, 134.2 mmHg
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.
| What the residual plot shows | What it suggests | What to do |
|---|---|---|
| A curve (U or inverted U) | The relation is not a straight line | Add a squared term, transform x or y, or fit a different model |
| A funnel: spread grows with the predicted value | The variance is not constant | Try a transformation of y, such as a logarithm, with a statistician's help |
| A few residuals much larger than the rest | Outliers: data-entry errors, or patients unlike the others | Check the records. Report the analysis with and without them |
| A pattern in the order of measurement | The residuals are not independent, for example repeated readings over time | Use methods for repeated or time-ordered data |
| A skewed histogram of residuals | The residuals are not roughly normal | Confidence 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.
The ages studied were 30 to 75
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.
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.
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.
| Feature | Multivariable | Multivariate |
|---|---|---|
| Outcome variables | One | Two or more, modelled together |
| Predictors | Several | One or more |
| Examples | Multiple linear, logistic or Cox regression with several predictors | The same outcome measured repeatedly on each patient, clustered data, MANOVA |
| Typical use | Adjusting for confounders, prediction models | Outcomes 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.
| Feature | Principal component regression | PLS regression |
|---|---|---|
| Components built from | The predictors only | The predictors and the outcome |
| First component | Captures the largest share of the variation in the predictors | Chosen to predict the outcome |
| Result | Components may not relate closely to the outcome | Components 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.
| Coefficient | What it tells you | Example in this chapter |
|---|---|---|
| Pearson r | Direction and closeness of a straight-line relation | Age and SBP, r = 0.82 |
| Spearman ρ | Consistency of rank order | Pain score and opioid dose |
| r² | Share of variation accounted for by the line | r = −0.32 → about 10% |
| b, linear regression | Change in the outcome per unit of the predictor | SBP +0.58 mmHg per year of age |
| Adjusted b | The same, with other predictors held constant | +0.52 mmHg per year, adjusted for BMI |
| OR = eb, logistic | Multiplies the odds of a yes/no outcome | Diabetes and wound infection, OR 2.25 |
| HR = eb, Cox | Multiplies the hazard of an event | HR 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.
A thesis predicts anastomotic leak (yes/no) from age, albumin, diabetes, smoking and operative time in 120 patients, of whom 15 had a leak.
Logistic regression. With 15 events, choose one or two predictors in advance. Five predictors will give unreliable odds ratios.
Pain score (0–10) is compared with total opioid dose in the first 24 hours.
A pain score is an ordinal scale. Use Spearman's ρ, not Pearson's r.
A transcutaneous bilirubin meter is compared with serum bilirubin in 80 neonates, and the resident reports r = 0.9 as proof that the meter can replace the blood test.
Correlation does not show agreement. Use a Bland–Altman plot of the differences.
Gestational diabetes is more common in women with a higher BMI, who are also older on average.
Logistic regression with BMI and age gives an odds ratio for BMI adjusted for age.
Two depression rating scales are scored on the same patients.
A high Spearman ρ shows the scales rank patients in a similar order. It does not show that their scores are interchangeable.
District female literacy rates are correlated with district infant mortality rates across 30 districts.
A correlation between district averages does not show the same relationship in individual families (the ecological fallacy).
Survival after chemotherapy, with some patients still alive when follow-up ends.
Time-to-event data with censoring need Cox regression, which reports hazard ratios.
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
Protocol sent back
The analysis plan says "correlation and multivariate analysis" without naming the coefficient, the outcome or the predictors.
A causal claim the thesis cannot support
A cross-sectional correlation written up as "vitamin D deficiency causes poor glycaemic control".
Viva questions on r²
Unable to explain that r = −0.32 accounts for about 10% of the variation in the outcome.
Misreading papers
Quoting an unadjusted odds ratio as the effect of an exposure, or accepting a logistic model with 12 predictors and 30 events.
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
- 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”.
- 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.
- 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.
- 1904
Charles Spearman
“The proof and measurement of association between two things” included comparison by rank, the basis of rank correlation.
- 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.
- 1967
Truett, Cornfield and Kannel
Published the first multivariable risk function for coronary heart disease from the Framingham study.
- 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.
- 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.
- 1996
Peduzzi and colleagues
In a simulation study, logistic regression coefficients were biased when there were fewer than 10 events per predictor variable.
- 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
“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”.
“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”.
“Describe all statistical methods, including those used to control for confounding.”
“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.”
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”
Going backwards, a relapse to an earlier state.
A method that describes how an outcome changes with one or more predictors, and predicts the outcome.
“Correlation”
Any connection between two things.
A number from −1 to +1 for how closely two variables vary together, along a straight line (Pearson) or in rank order (Spearman).
“Multivariate”
Involving many variables.
Strictly, a model with two or more outcome variables. A model with one outcome and several predictors is multivariable.
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- Definition: a measure of the direction and closeness of the straight-line relation between two quantitative variables. Range −1 to +1, no units.
- Formula: r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² × Σ(y − ȳ)²]. “Product-moment” refers to the mean of the products of the deviations from the means.
- 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.
- Scatter diagram: draw it first. r = +1 or −1, all points on a line. r = 0, no straight-line relation.
- 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%.
- Assumptions: two quantitative variables, a straight-line relation, independent pairs, no extreme outliers, and roughly normal distributions for tests and confidence intervals.
- 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).
- 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.
- Partial correlation: the correlation between two variables with a third held constant, rxy·z = (rxy − rxz × ryz) ÷ √[(1 − rxz²)(1 − ryz²)].
- 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| Feature | Pearson product-moment (r) | Spearman rank (ρ) |
|---|---|---|
| Type | Parametric | Non-parametric |
| Uses | Actual values | Ranks of the values |
| Formula | Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² × Σ(y − ȳ)²] | 1 − 6Σd² ÷ [n(n² − 1)], d = difference in ranks |
| Relation measured | Straight line | Consistently rising or falling (monotonic) |
| Data | Both quantitative, roughly normal | Ordinal scores, skewed data, outliers |
| Example | Age and SBP | Pain 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| Feature | Correlation coefficient (r) | Coefficient of variation (CV) |
|---|---|---|
| Describes | Relation between two variables | Spread 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 units | A percentage, no units |
| Use | Strength and direction of association | Comparing variability of measurements on different scales, and precision of laboratory assays |
| Example | Age and SBP, r = 0.82 | Hb 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- Definition: a method that describes the relation between an outcome (dependent variable) and one or more predictors (independent variables), and predicts the outcome.
- 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.
- Simple linear regression: y = a + bx, fitted by least squares. b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², a = ȳ − b x̄.
- Worked example (teaching data): SBP = 103.65 + 0.58 × age, b 95% CI 0.26 to 0.91, r² = 0.68.
- Assumptions: straight-line relation, independent observations, residuals with constant spread and roughly normal distribution.
- 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.
- 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.
- 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.
- Multiple regression: each b is adjusted for the other predictors. Watch for multicollinearity and overfitting.
- Uses: prediction, adjustment for confounding, risk scores, laboratory calibration.
- Reporting (SAMPL): the regression equation, the coefficients with confidence intervals, and how assumptions, outliers and missing data were handled.
- Pitfalls: extrapolation beyond the data, causal claims from observational data, regression towards the mean.
Logistic regression
DM Neurology 2009- Definition: regression for a binary outcome, such as good or poor outcome after stroke, with one or more predictors.
- Why not linear regression: a straight line can predict probabilities below 0 or above 1.
- Model: ln[p ÷ (1 − p)] = a + b₁x₁ + … + bₖxₖ. The left side is the logit (log odds).
- 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.
- 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.
- Types: binary, multinomial (unordered categories), ordinal (ordered categories).
- 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.
- Model checking: discrimination (C statistic, area under the ROC curve) and calibration (for example the Hosmer–Lemeshow test).
- 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
- Problem: many predictors that are highly correlated, or more predictors than subjects. Least squares estimates are unreliable or impossible.
- Idea: build a few components (latent variables), each a weighted combination of the predictors, with weights chosen so the components predict the outcome.
- 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.
- Checking: prediction quality is assessed by cross-validation, such as the bootstrap or jackknife.
- 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.
- Uses: spectra in chemistry (chemometrics), brain imaging, large laboratory or “omics” panels.
- Origin: proposed by Herman Wold in the 1960s.
- 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.
- ×4Regression analysis
- ×4Correlation coefficient
- ×2Multivariate analysis
- ×1Write two methods of correlation commonly used in research methodology
- ×1Correlation coefficient and Pearson product-moment correlation coefficient
- ×1What is correlation coefficient? What is its significance?
- ×1Explain regression and correlation in clinical studies with appropriate examples
- ×1Correlation and Regression
- ×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 Analysis
- ×1Correlation coefficient and coefficient of variation
- ×1What is the role of correlation and regression coefficient in statistical analysis?
- ×1Logistic regression
Further reading