Skip to main content
v2026.11,858 entries · CC-BY 4.0

What Is a Lurking Variable? Definition, Examples and How to Spot One

A lurking variable affects the relation between variables in an analysis without being included. Definition, examples, a worked example and code.

Written and maintained by CASRAI Editorial Board

Last updated

What is a lurking variable?

A lurking variable is a variable that is not included in an analysis but affects the relation between the variables that are included (Wolfram MathWorld, “Lurking Variable”). It can create an association that is not there, hide one that is, or change its direction, which is why a correlation between two measured variables cannot by itself show that one causes the other.

Lurking variables are the practical reason behind the rule that correlation does not establish causation. If you find that X and Y move together, a third variable Z that influences both can produce the pattern without any causal link between X and Y. See correlation vs causation for the wider argument and spurious correlation for cases where the pattern is pure coincidence rather than a shared driver.

Lurking variable vs confounding variable

MathWorld notes that a lurking variable “may act as a confounding variable, creating or obscuring an association between an independent variable and a dependent variable.” In other words the two ideas overlap: the definition is about a variable left out of the analysis, while a confounder is a third variable that distorts the exposure-outcome relation. Conventions vary between textbooks, so check which one your course or reviewer follows.

Term Typical use Where to read more
Lurking variable A third variable left out of the analysis that affects the relation between the included variables This page
Confounding variable A third variable associated with both the exposure and the outcome, handled in the design or the model Confounding variable
Omitted variable The same idea framed as a regression problem: a relevant predictor missing from the model biases the estimates Omitted variable bias
Common cause The same idea drawn as a causal graph: Z points to both X and Y DAGs and confounder selection

Lurking variable examples

Education, contraception use and appliance ownership

Lane’s Online Statistics Education chapter on causation describes a case where contraception use and the number of appliances in a household are correlated, and explains that “the third variable of education level affects both.” Neither causes the other; the third variable accounts for the pattern (Lane, Online Statistics Education, Causation).

Temperature, ice cream sales and beach incidents (illustrative)

Suppose a town records daily ice cream sales and the number of beach incidents. Both rise on hot days, so they correlate strongly. Temperature is the lurking variable. The worked example below uses a small invented data set, labelled as such, to put numbers on this.

A masked relationship (illustrative)

A lurking variable does not only manufacture associations. If a treatment is offered more often to people who are already worse off, a pooled comparison can show no benefit, or even a harm, while a comparison within comparable groups shows a benefit. This is the “obscuring” case in the MathWorld definition, and the reason analysts compare like with like.

Worked example: how much of a correlation is the lurking variable?

Illustrative data, invented for teaching; not from any real town. Eight days, with temperature Z in °C, ice cream sales X (units sold) and beach incidents Y (count).

Day Z (temperature) X (sales) Y (incidents)
1 18 110 2
2 21 150 3
3 24 150 4
4 27 210 3
5 30 230 6
6 33 240 5
7 36 300 8
8 39 330 9

Formula: partial correlation

The correlation between X and Y with Z held constant is

rXY·Z = (rXY − rXZ × rYZ) / √[(1 − rXZ²)(1 − rYZ²)]

where rXY is the Pearson correlation of X and Y, rXZ that of X and Z, and rYZ that of Y and Z. The numerator removes the part of the X-Y association that runs through Z; the denominator rescales what remains.

Arithmetic

  1. Pearson correlations from the table: rXY = 0.9329, rXZ = 0.9855, rYZ = 0.9305.
  2. Numerator: 0.9329 − (0.9855 × 0.9305) = 0.9329 − 0.9169 = 0.0160.
  3. Denominator: 1 − 0.9855² = 1 − 0.9711 = 0.0289, and 1 − 0.9305² = 1 − 0.8658 = 0.1342. Their product is 0.003876, whose square root is 0.0623.
  4. rXY·Z = 0.0160 / 0.0623 = 0.257.

The raw correlation of 0.93 falls to 0.26 once temperature is held constant. With n = 8 the partial correlation has n − 3 = 5 degrees of freedom: t = 0.257 × √(5 / (1 − 0.257²)) = 0.59, p = .578. Within this invented sample, nearly all of the apparent link between sales and incidents runs through temperature.

Interpretation: reading the change

What happens when Z is controlled What it suggests
Association shrinks toward zero Z accounts for most of the X-Y association (a spurious or inflated relation)
Association grows or appears Z was masking a relation between X and Y
Association reverses sign Z was distorting the direction; check the data for subgroup structure
Association barely changes Z is not a strong lurking variable for this pair, though other unmeasured variables may be

These readings describe what adjusting for one measured variable does. They do not prove which variables matter; that depends on the causal structure, which is the subject of causal analysis.

Assumptions and common mistakes

  • Adjusting for a variable does not remove all lurking variables. It addresses only the ones you measured. Others may remain.
  • Partial correlation assumes linear relations among X, Y and Z, and the usual Pearson assumptions apply; see the correlation coefficient guide.
  • Do not adjust for everything. Controlling for a variable that sits on the causal path between X and Y removes a real effect rather than a bias.
  • Small samples make partial correlations unstable, as the p = .578 above shows with n = 8.

How to defend against lurking variables

Random assignment of the exposure spreads unmeasured variables across groups by chance, which is why experiments handle lurking variables better than observational studies. In observational work, analysts compare within strata, add measured covariates to the model, and test how sensitive the conclusion is to an unmeasured variable.

How to report it (APA example)

APA 7th edition reports correlation coefficients and p values without a leading zero because they cannot exceed 1. For the example above:

Ice cream sales and beach incidents were strongly correlated, r(6) = .93, p < .001. After controlling for daily temperature, the partial correlation was small and not statistically significant, r(5) = .26, p = .578.

How to calculate it in Excel, R or Python

Excel

Put Z, X and Y in columns A, B and C (rows 2 to 9). Compute the three correlations with =CORREL(B2:B9,C2:C9) (rXY), =CORREL(B2:B9,A2:A9) (rXZ) and =CORREL(C2:C9,A2:A9) (rYZ), store them in E1, E2 and E3, then use =(E1-E2*E3)/SQRT((1-E2^2)*(1-E3^2)).

R

z = c(18,21,24,27,30,33,36,39)
x = c(110,150,150,210,230,240,300,330)
y = c(2,3,4,3,6,5,8,9)
rxy = cor(x,y); rxz = cor(x,z); ryz = cor(y,z)
(rxy - rxz*ryz) / sqrt((1-rxz^2)*(1-ryz^2))   # 0.257

Python

import numpy as np
z = np.array([18,21,24,27,30,33,36,39])
x = np.array([110,150,150,210,230,240,300,330])
y = np.array([2,3,4,3,6,5,8,9])
r = np.corrcoef([x, y, z])
rxy, rxz, ryz = r[0,1], r[0,2], r[1,2]
print((rxy - rxz*ryz) / np.sqrt((1-rxz**2)*(1-ryz**2)))  # 0.257

FAQ

What is a lurking variable?

A variable left out of an analysis that nevertheless affects the relation between the variables that are included. It can create, hide or reverse an association.

What is an example of a lurking variable?

Education level in Lane’s example: it affects both contraception use and appliance ownership, which explains why those two correlate. Temperature in the ice cream example above works the same way.

Is a lurking variable the same as a confounding variable?

They overlap. MathWorld says a lurking variable “may act as a confounding variable”, and both describe a third variable that distorts the relation between two others. Conventions differ between texts, so follow the one your course or reviewer uses.

How do you control for a lurking variable?

Randomise assignment where you can; otherwise measure the suspected variable and compare within strata or include it as a covariate, then check how sensitive the result is to variables you could not measure.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about What Is a Lurking Variable? Definition, Examples and How to Spot One

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.