Thursday, November 12, 2026

Omitted Variable Bias: The Formula, a Python Example and Fixes

Say a product team launches an AI writing assistant inside an online store’s seller dashboard. A month later, an analyst regresses weekly orders on hours spent with the assistant and finds that each extra hour goes with 3.3 more orders. The team wants to put that number in the launch review. The trouble is that the most engaged sellers use every new feature first, and they also sell more, with or without help.

Omitted variable bias is the error in a regression estimate that appears when a variable that affects the outcome, and is correlated with the variable you care about, is left out of the model. The estimate then picks up part of the missing variable’s effect. The size of the error follows a simple formula: the omitted variable’s effect on the outcome times its association with the included variable. This guide explains the formula, checks it on a simulation where we know the true answer, and covers what to do when the missing variable cannot be measured.

Key Takeaways

  • Omitted variable bias needs two things at once: the left-out variable affects the outcome, and it is correlated with a variable in the model. If either is missing, there is no bias.
  • The bias equals the omitted variable’s effect on the outcome multiplied by the slope from regressing the omitted variable on the included one. That tells you its direction before you run anything.
  • In our simulation the true effect was 2.0. Leaving out engagement gave 3.268; including it gave 2.028. The gap of 1.240 matched the formula to three decimals.
  • The bias can reverse the sign of an effect. In a second simulation a true effect of +1.0 showed up as -0.899.
  • When the confounder cannot be measured, use a design that removes it (an experiment, panel data with fixed effects, an instrument) or report how strong a hidden variable would need to be to change your conclusion.

What Is Omitted Variable Bias?

A regression coefficient answers a narrow question: how much does the outcome change with this variable, holding the other variables in the model fixed? Anything not in the model is not held fixed. If a missing variable moves together with the one you are studying, the coefficient absorbs part of its effect.

Two conditions have to hold for that to cause bias:

  1. The omitted variable affects the outcome. In the opening scenario, engaged sellers get more orders.
  2. The omitted variable is correlated with an included variable. Engaged sellers also spend more time with the new assistant.

If engagement had no effect on orders, leaving it out would cost some precision but not bias the estimate. If engagement were unrelated to assistant use, the same would be true. The bias comes from the overlap. This is why the problem is often called confounding: the omitted variable is a common cause of both the treatment and the outcome.

Omitted variable bias does not shrink with more data. A larger sample gives a tighter confidence interval around the wrong number. In the simulation below, the short regression’s 95% interval runs from 3.190 to 3.345 and does not come close to the true value of 2.0.

The Omitted Variable Bias Formula

Suppose the true model is:

orders = b0 + b1 * feature_use + g * engagement + error

but you fit the short model without engagement:

orders = c0 + c1 * feature_use + error

Then, in the sample, the short coefficient equals the long one plus a bias term:

c1 = b1 + g * d

Here g is the effect of engagement on orders, taken from the long regression, and d is the slope from regressing engagement on feature use. This identity holds exactly for ordinary least squares (OLS) estimates in any sample, not only on average. The standard derivation needs nothing more than the algebra of linear regression.

The formula’s real use is telling you the direction of the bias before you have data on the missing variable. You only need the signs:

Omitted variable and included variable move together (d > 0) They move in opposite directions (d < 0)
Omitted variable raises the outcome (g > 0) Estimate too high Estimate too low
Omitted variable lowers the outcome (g < 0) Estimate too low Estimate too high

For the seller dashboard, engagement raises orders and goes with more assistant use, so both signs are positive and the estimate of 3.3 orders per hour is too high. You know that before measuring engagement at all.

A Runnable Example in Python

The script below builds data where we set the true effect of feature use on orders to 2.0. Engagement raises both feature use and orders. It then fits the short and long regressions, checks the bias formula, tries a noisy proxy for engagement, and shows a case where the bias flips the sign. It uses NumPy and statsmodels OLS (we ran it with statsmodels 0.15.0 and NumPy 2.5.4).

import numpy as np
import statsmodels.api as sm

rng = np.random.default_rng(42)
n = 5_000

# Simulated data: engagement drives both feature use and orders.
engagement = rng.normal(0, 1, n)                      # the variable we might leave out
feature_use = 0.6 * engagement + rng.normal(0, 1, n)  # hours using the AI feature
orders = 2.0 * feature_use + 3.0 * engagement + rng.normal(0, 2, n)  # true effect: 2.0

# 1. Short regression: engagement left out.
short = sm.OLS(orders, sm.add_constant(feature_use)).fit()
# 2. Long regression: engagement included.
X_long = sm.add_constant(np.column_stack([feature_use, engagement]))
long = sm.OLS(orders, X_long).fit()

print(f"short regression: {short.params[1]:.3f} (95% CI {short.conf_int()[1][0]:.3f} to {short.conf_int()[1][1]:.3f})")
print(f"long regression:  {long.params[1]:.3f} (95% CI {long.conf_int()[1][0]:.3f} to {long.conf_int()[1][1]:.3f})")

# 3. Check the omitted variable bias formula: bias = gamma * delta,
# gamma = effect of engagement on orders (from the long regression),
# delta = slope from regressing engagement on feature_use.
gamma = long.params[2]
delta = sm.OLS(engagement, sm.add_constant(feature_use)).fit().params[1]
print(f"gamma = {gamma:.3f}, delta = {delta:.3f}, gamma * delta = {gamma * delta:.3f}")
print(f"short - long = {short.params[1] - long.params[1]:.3f}")

# 4. A noisy proxy for engagement (for example, sessions last month) fixes part of it.
proxy = engagement + rng.normal(0, 1, n)
X_proxy = sm.add_constant(np.column_stack([feature_use, proxy]))
print(f"with a noisy proxy: {sm.OLS(orders, X_proxy).fit().params[1]:.3f}")

# 5. The bias can flip the sign: a confounder that pushes the other way.
cost = rng.normal(0, 1, n)                        # e.g. price sensitivity
discount_use = 0.8 * cost + rng.normal(0, 1, n)   # price-sensitive users use discounts more
spend = 1.0 * discount_use - 4.0 * cost + rng.normal(0, 2, n)  # true effect: +1.0
flip_short = sm.OLS(spend, sm.add_constant(discount_use)).fit().params[1]
flip_long = sm.OLS(spend, sm.add_constant(np.column_stack([discount_use, cost]))).fit().params[1]
print(f"sign flip: short {flip_short:.3f}, long {flip_long:.3f}")

Output:

short regression: 3.268 (95% CI 3.190 to 3.345)
long regression:  2.028 (95% CI 1.973 to 2.083)
gamma = 2.950, delta = 0.420, gamma * delta = 1.240
short - long = 1.240
with a noisy proxy: 2.738
sign flip: short -0.899, long 0.989

Reading the Results

The short regression overstates the effect by about 63%. It reports 3.268 orders per hour of feature use when the true value is 2.0. Its confidence interval is narrow and confidently wrong, because 5,000 rows make the estimate precise without making it right.

The long regression recovers the truth. With engagement in the model, the estimate is 2.028, and the 95% interval (1.973 to 2.083) contains 2.0.

The formula matches exactly. Engagement’s effect on orders in the long regression is 2.950, and the slope of engagement on feature use is 0.420. Their product, 1.240, is the same as the gap between the short and long estimates. That is the identity from the previous section, checked on real numbers.

A noisy proxy helps, but only partly. Adding a proxy (engagement plus noise, standing in for something like last month’s session count) moves the estimate from 3.268 to 2.738. It closes about 43% of the gap. Measurement error in a control means it only absorbs part of the confounding, so a weak proxy should not be reported as if it solved the problem.

Before trusting any of these numbers on real data, check the inputs. A control column that arrives with missing values or wrong types can quietly change which rows enter each regression. Our guide to data validation with Pandera shows how to catch that at load time.

When the Bias Flips the Sign

The last line of the output is the case that causes the most damage in practice. In that simulation, using a discount code raises spending by 1.0 per unit. But price-sensitive customers are both more likely to use discounts and less likely to spend. Price sensitivity lowers the outcome (g is negative) and moves with discount use (d is positive), so the table above says the estimate will be too low.

It is too low by enough to change sign: the short regression reports -0.899, which reads as “discounts reduce spending.” Including price sensitivity gives 0.989. A team reading the short model would cut a program that works.

The pattern is common wherever people choose their own treatment: who opts into a feature, who takes a training course, who gets assigned to a premium support tier. Whenever the people who receive something differ from those who do not in a way that also drives the outcome, write down the likely confounder and use the sign table to see which way it pushes.

How to Reduce Omitted Variable Bias

Measure and Include the Confounder

The direct fix is the one in the simulation: find the common cause and add it to the model. Start from how the treatment is assigned. Ask who gets more of it and why, then look for data on that reason. For the seller dashboard, account age, past order volume and login frequency are all candidates for engagement.

Do Not Add Every Variable You Have

More controls are not always safer. Two kinds of variable make estimates worse when added:

  • Mediators are variables the treatment changes on the way to the outcome. If the AI assistant raises orders by improving listing quality, controlling for listing quality removes part of the effect you want to measure.
  • Colliders are variables caused by both the treatment and the outcome. Controlling for one creates a correlation that was not there.

The rule of thumb: control for causes of the treatment and outcome that happen before the treatment, not for things that happen after it. Automatic selection methods such as stepwise regression do not know which is which, so they are not a fix for confounding.

Use a Design That Removes the Confounder

When the confounder cannot be measured, change the design instead of the model:

  • Randomized experiments. If you assign who gets the feature at random, engagement cannot be correlated with treatment, so condition two fails and the bias goes away. For a product launch, a staged rollout to random users is often the cheapest version.
  • Panel data with fixed effects. If the confounder is stable over time (a seller’s baseline engagement), comparing each seller with themselves before and after adoption removes it.
  • Difference-in-differences. Compare the change in outcomes for a group that got the treatment with the change for a group that did not, over the same period.
  • Instrumental variables. Find something that shifts the treatment but affects the outcome only through it, such as a random invitation to try the feature.

Each design trades the omitted variable assumption for a different one. Write that assumption down in the analysis, so readers can judge it.

How Strong Would a Hidden Variable Have to Be?

Sometimes you cannot measure the confounder and cannot change the design. Then the honest move is a sensitivity analysis: report how strong an omitted variable would need to be to erase or reverse your result.

Carlos Cinelli and Chad Hazlett’s paper “Making Sense of Sensitivity: Extending Omitted Variable Bias” (Journal of the Royal Statistical Society, Series B, 2020) extends the formula above into this kind of check. It expresses the bias in terms of how much of the remaining variation in the treatment and the outcome a hidden confounder would explain. You can then compare that against the observed controls: “a confounder would have to be three times as strong as past order volume to explain away this effect” is a statement a reader can weigh.

Even without the full method, the simple formula gives a quick check. If you think engagement raises orders by about 3 per standard deviation and moves with feature use at a slope of about 0.4, the bias is about 1.2. If your estimate is 3.3, the effect is probably real but smaller, closer to 2.

Report the uncertainty of the adjusted estimate as well. Our guide to the Poisson bootstrap shows one way to get confidence intervals on large or streaming data.

Omitted Variable Bias vs Selection Bias

The two are easy to confuse because both come from the data not being a clean comparison. Omitted variable bias is about a missing column: a common cause that is not in the model. Selection bias is about missing rows: the outcome is only observed for a non-random part of the sample, such as wages only for people who work.

The fixes differ. Omitted variable bias calls for the confounder, a better design or a sensitivity analysis. Selection bias calls for modeling who is observed, as in our guide to the Heckman selection model. Heckman’s own framing treats selection as a special case of an omitted variable: the selection correction term is the variable the naive regression leaves out.

A related habit helps with both: compare your model against a simple baseline before trusting it. The idea is the same as using a dummy classifier as a baseline in machine learning. Here the baseline is the short regression, and the question is how much the estimate moves when you add the controls you believe in.

Back to the Feature Launch

The analyst in the opening scenario had a precise number that answered the wrong question. In data built to look like theirs, the 3.3 orders per hour came mostly from who chose to use the assistant: adding engagement brought the estimate down to 2.0, and the bias formula explained the gap to the third decimal. The cheaper fix for the next launch is a staged rollout to random sellers, which removes the problem before any regression is run.

Frequently Asked Questions

Does a Bigger Sample Fix Omitted Variable Bias?

No. More data makes the estimate more precise, not more correct. The confidence interval narrows around the biased value, which can make the wrong answer look more convincing. Only including the confounder, changing the design or bounding the bias deals with it.

Is a Low R-Squared a Sign of Omitted Variable Bias?

Not by itself. A model can explain little of the variation in the outcome and still estimate one effect without bias, for example in a randomized experiment. A model with a high R-squared can still be badly biased if the confounder is missing. Bias depends on whether the omitted variable is correlated with the one you care about, not on how much variance the model explains.

Can Machine Learning Models Avoid Omitted Variable Bias?

Not if the goal is a causal effect. A flexible model can predict the outcome well using whatever variables it has, but it cannot separate the effect of one variable from a common cause that is not in the data. Prediction and causal estimation are different tasks. Methods built for causal questions, such as double machine learning, still assume the important confounders are measured.

What Is the Difference Between a Confounder and a Control Variable?

A confounder is a common cause of the treatment and the outcome. A control variable is anything you put in the model. Good control variables are confounders, or close proxies for them. Variables caused by the treatment (mediators) or by both treatment and outcome (colliders) are bad controls and can add bias instead of removing it.

Disclaimer: The content on this website reflects the views of contributing authors and not necessarily those of Generative AI Lab. This site may contain sponsored content, affiliate links, and material created with generative AI. Thank you for your support.

Generative AI Lab mascot
Generative AI Lab Editorial Team
Articles researched, written and edited by the Generative AI Lab team. About Generative AI Lab

Must read

- Advertisement -spot_img

More articles

- Advertisement -spot_img

Latest articles

Available for Amazon Prime