Skip to content

Bias Analysis: Selection, Misclassification & the E-value

A confidence interval describes random error and nothing else. A study that loses participants unevenly, measures the exposure with error, or lacks a confounder can put a narrow interval around the wrong number. Quantitative bias analysis asks how far a systematic error of a stated size moves the estimate, and it returns a corrected estimate to set beside the conventional one. This page corrects a risk ratio for selection bias and for exposure misclassification, carries the uncertainty about the bias parameters through the correction, and computes the E-value for unmeasured confounding.

Download birth_cohort_bias.csv into your working directory. The invented table has 8,000 rows, one per birth in a regional cohort, and four 0/1 columns: smoker (the mother smoked during pregnancy, as a cotinine assay would show), sga (the infant was small for gestational age), participated (the mother returned a follow-up questionnaire) and reported_smoker (her own answer, at the first antenatal visit, to whether she smoked). The birth is the unit of analysis.

The values come from a simulation with known answers. Smoking was assigned at random to 25% of the mothers, so nothing confounds it. The risk of a small-for-gestational-age birth is 0.08 without smoking and 0.16 with it, which makes the true risk ratio 2.0 and the true odds ratio 2.19. A real study would not have the smoker column. It is in the file so that each correction can be judged against the truth. The code keeps a 2x2 table as four cells: a1 and b1 are the exposed cases and non-cases, and a0 and b0 the unexposed cases and non-cases. The risk measures page derives the two ratios and the Wald interval that the code uses.

library(episensr)
library(EValue)
library(ggplot2)
births <- read.csv("birth_cohort_bias.csv")
dir.create("outputs", showWarnings = FALSE)
#' Count the cells of a 0/1 exposure by 0/1 outcome table.
#'
#' @param exposure,outcome Vectors of 0 and 1.
#' @return A list with a1, b1 (exposed cases, non-cases), a0 and b0.
CountCells <- function(exposure, outcome) {
list(a1 = sum(exposure == 1 & outcome == 1),
b1 = sum(exposure == 1 & outcome == 0),
a0 = sum(exposure == 0 & outcome == 1),
b0 = sum(exposure == 0 & outcome == 0))
}
#' Compute the risk ratio of a table. The cells may be vectors of draws.
#'
#' @param cells A list with a1, b1, a0 and b0.
#' @return The risk ratio.
RiskRatio <- function(cells) {
(cells$a1 / (cells$a1 + cells$b1)) / (cells$a0 / (cells$a0 + cells$b0))
}
#' Compute the risk ratio of observed counts with 95% Wald limits.
#'
#' @param cells A list with a1, b1, a0 and b0.
#' @return The estimate, the limits and the SE of the log risk ratio.
WaldLimits <- function(cells) {
se <- sqrt(1 / cells$a1 - 1 / (cells$a1 + cells$b1) +
1 / cells$a0 - 1 / (cells$a0 + cells$b0))
estimate <- RiskRatio(cells)
c(estimate = estimate, lower = estimate * exp(-qnorm(0.975) * se),
upper = estimate * exp(qnorm(0.975) * se), se = se)
}
#' Format a table as one line with its odds ratio and risk ratio.
#'
#' @param label A short name for the table.
#' @param cells A list with a1, b1, a0 and b0.
#' @param wald TRUE to add the Wald limits of the risk ratio.
#' @return One line of text.
TableLine <- function(label, cells, wald = FALSE) {
odds_ratio <- (cells$a1 * cells$b0) / (cells$b1 * cells$a0)
line <- sprintf("%-17s %5.0f %5.0f %5.0f %5.0f %.3f %.3f", label,
cells$a1, cells$b1, cells$a0, cells$b0, odds_ratio,
RiskRatio(cells))
if (wald) {
limits <- WaldLimits(cells)
line <- sprintf("%s [%.3f, %.3f]", line, limits[["lower"]],
limits[["upper"]])
}
paste0(line, "\n")
}
header <- sprintf("%-17s %5s %5s %5s %5s %-5s %s\n", "Table", "a1", "b1",
"a0", "b0", "OR", "RR [95% CI]")
full <- CountCells(births$smoker, births$sga)
full_limits <- WaldLimits(full)
cat(header, TableLine("Full cohort", full, wald = TRUE), sep = "")
Table a1 b1 a0 b0 OR RR [95% CI]
Full cohort 319 1678 495 5508 2.115 1.937 [1.699, 2.209]

With the true smoking status of every birth, 319 of 1,997 smokers and 495 of 6,003 nonsmokers had a small-for-gestational-age infant, risks of 0.160 and 0.082. The risk ratio is 1.937 with a 95% interval from 1.699 to 2.209, which contains the true 2.0. This is what a study with complete follow-up and a perfect exposure measure would report. Each section below damages it in one way.

Suppose smoking is known from the assay, but the analysis is limited to the mothers who returned the questionnaire. In this simulation, 75% of the mothers of a small-for-gestational-age infant returned it, whatever their smoking status. Among the other mothers, 60% of the nonsmokers and 40% of the smokers did. Participation depends on the exposure and the outcome together.

Each participant stands for 1/S births of her kind, where S is the selection probability of her cell, so dividing the four observed cells by their selection probabilities rebuilds the table of the source population. For the odds ratio the whole correction is one number, the selection bias factor (Sa1 × Sb0) / (Sb1 × Sa0): the odds ratio among participants is the odds ratio of the source population times that factor. In R, selection() from episensr makes the same correction from the four probabilities, in the order exposed cases, unexposed cases, exposed non-cases, unexposed non-cases. EValue exports a function of the same name and masks it when it is loaded second, so the code writes episensr::selection(). The Python tab has the hand calculation only.

The bias factor is 1 whenever the four probabilities multiply, meaning that participation is a term for the exposure times a term for the outcome. Participation that depends on the exposure only, or on the outcome only, is the plainest case. The last rows of the output apply four participation patterns to the expected table of 10,000 births from the source population, 2,500 smokers with a risk of 0.16 and 7,500 nonsmokers with a risk of 0.08, so the result has no sampling error.

answered <- births[births$participated == 1, ]
observed <- CountCells(answered$smoker, answered$sga)
selection_prob <- list(a1 = 0.75, b1 = 0.40, a0 = 0.75, b0 = 0.60)
cat(header, TableLine("Participants", observed, wald = TRUE),
TableLine("Corrected", Map("/", observed, selection_prob)), sep = "")
bias_factor <- (selection_prob$a1 * selection_prob$b0) /
(selection_prob$b1 * selection_prob$a0)
cat(sprintf("Selection bias factor of the odds ratio %.2f\n", bias_factor))
# Filled by column, the cells give episensr its layout: cases in row 1,
# the exposed in column 1.
package_result <- episensr::selection(
matrix(unlist(observed), nrow = 2), bias_parms = c(0.75, 0.75, 0.40, 0.60)
)
cat(sprintf("episensr: odds ratio %.3f, risk ratio %.3f, factor %.2f\n",
package_result$adj_measures[2, 1],
package_result$adj_measures[1, 1], package_result$selbias_or))
source_population <- list(a1 = 400, b1 = 2100, a0 = 600, b0 = 6900)
patterns <- list(
"Smoking only" = list(a1 = 0.40, b1 = 0.40, a0 = 0.60, b0 = 0.60),
"Outcome only" = list(a1 = 0.75, b1 = 0.50, a0 = 0.75, b0 = 0.50),
"Both, multiplied" = list(a1 = 0.45, b1 = 0.30, a0 = 0.75, b0 = 0.50),
"Both, this cohort" = list(a1 = 0.75, b1 = 0.40, a0 = 0.75, b0 = 0.60)
)
cat(TableLine("All 10,000 births", source_population))
factors <- c()
for (name in names(patterns)) {
share <- patterns[[name]]
cat(TableLine(name, Map("*", source_population, share)))
factors <- c(factors, (share$a1 * share$b0) / (share$b1 * share$a0))
}
cat(sprintf("Bias factors: %s\n",
paste(sprintf("%.2f", factors), collapse = ", ")))
Table a1 b1 a0 b0 OR RR [95% CI]
Participants 229 660 367 3367 3.183 2.621 [2.260, 3.039]
Corrected 305 1650 489 5612 2.122 1.947
Selection bias factor of the odds ratio 1.50
episensr: odds ratio 2.122, risk ratio 1.947, factor 1.50
All 10,000 births 400 2100 600 6900 2.190 2.000
Smoking only 160 840 360 4140 2.190 2.000
Outcome only 300 1050 450 3450 2.190 1.926
Both, multiplied 180 630 450 3450 2.190 1.926
Both, this cohort 300 840 450 4140 3.286 2.684
Bias factors: 1.00, 1.00, 1.00, 1.50

The 4,623 participants give a risk ratio of 2.621 with a 95% interval from 2.260 to 3.039. The interval excludes both the true 2.0 and the full-cohort estimate of 1.937. The questionnaire kept 75% of the smokers with a small infant and 40% of the smokers without one, so the smokers who remain are sicker than smokers are.

The bias factor is (0.75 × 0.60) / (0.40 × 0.75) = 1.50. The observed odds ratio of 3.183 divided by 1.50 is 2.122, the odds ratio of the corrected table, against 2.115 in the full cohort. The corrected risk ratio is 1.947, against 1.937, and episensr::selection() returns the same numbers. The corrected cells are close to the full cohort without being equal to it, 305 exposed cases against 319, because the 229 who answered are one random draw at a probability of 0.75. The correction removes the expected bias and leaves the sampling error of who answered.

The code prints no interval for the corrected table. Its cells are observed counts divided by probabilities, larger than the counts that were observed, and the Wald formula applied to them would give an interval that is too narrow. In practice the four probabilities come from outside the study table, for example from a birth registry that records smoking and birth weight for participants and nonparticipants alike.

When participation depends on smoking only, both ratios keep their true values of 2.190 and 2.000. When it depends on the outcome only, the odds ratio stays at 2.190 and the risk ratio moves to 1.926, because cases are over-represented and the proportions among participants are no longer risks. That is the sampling scheme of a case-control study, and the reason that design reports an odds ratio.

The third pattern depends on both variables. Smokers participate at 0.6 times the rate of nonsmokers among cases (0.45 / 0.75) and among non-cases (0.30 / 0.50), the factor is 1.00, and the odds ratio is intact. The fourth pattern is this cohort: smoking lowers participation among non-cases and not among cases, the factor is 1.50, and the expected odds ratio and risk ratio are 3.286 and 2.684. The question to ask of a study is whether the exposure changed participation by a different factor in cases than in non-cases. The causal diagrams page draws this structure, in which participation is a common effect of the exposure and the outcome and an analysis of participants conditions on it.

Now keep all 8,000 births and use smoking as the mothers reported it. The simulation gives self-report a sensitivity of 0.75, the probability that a smoker says yes, and a specificity of 0.97, the probability that a nonsmoker says no. Both are the same for mothers of small infants and for all other mothers, which is the definition of non-differential misclassification.

Among the cases, the number who report smoking is Se × a1 + (1 − Sp) × a0: the smokers who say yes plus the nonsmokers who say yes. Solving for the true count gives a1 = (reported a1 − (1 − Sp) × cases) / (Se + Sp − 1), and the same formula holds among the non-cases. CorrectExposure() applies it, and MisclassifyExposure() runs the misclassification forward. In R, misclass() from episensr makes the correction, with bias_parms in the order sensitivity among cases, sensitivity among non-cases, then the two specificities.

Recall bias is the usual source of differential misclassification. The exposure is asked about after the outcome is known, and the outcome changes the answer: a mother whose infant was small may search her memory harder, or may conceal that she smoked. The scenarios below misclassify the expected source table, where the true risk ratio is 2.00. Each column gives the value among cases first and among non-cases second.

#' Correct a reported table for exposure misclassification.
#'
#' @param cells A list with the reported a1, b1, a0 and b0.
#' @param accuracy Sensitivity among cases and non-cases, then specificity
#' among cases and non-cases. Each may be a vector of draws.
#' @return A list with the corrected cells, negative when impossible.
CorrectExposure <- function(cells, accuracy) {
cases <- cells$a1 + cells$a0
noncases <- cells$b1 + cells$b0
a1 <- (cells$a1 - (1 - accuracy[[3]]) * cases) /
(accuracy[[1]] + accuracy[[3]] - 1)
b1 <- (cells$b1 - (1 - accuracy[[4]]) * noncases) /
(accuracy[[2]] + accuracy[[4]] - 1)
list(a1 = a1, b1 = b1, a0 = cases - a1, b0 = noncases - b1)
}
#' Misclassify the exposure of a true table, in expectation.
#'
#' @param cells A list with the true a1, b1, a0 and b0.
#' @param accuracy As in CorrectExposure().
#' @return A list with the expected cells of the reported table.
MisclassifyExposure <- function(cells, accuracy) {
a1 <- accuracy[[1]] * cells$a1 + (1 - accuracy[[3]]) * cells$a0
b1 <- accuracy[[2]] * cells$b1 + (1 - accuracy[[4]]) * cells$b0
list(a1 = a1, b1 = b1, a0 = cells$a1 + cells$a0 - a1,
b0 = cells$b1 + cells$b0 - b1)
}
reported <- CountCells(births$reported_smoker, births$sga)
reported_limits <- WaldLimits(reported)
cat(header, TableLine("Reported smoking", reported, wald = TRUE),
TableLine("Corrected", CorrectExposure(reported, c(0.75, 0.75, 0.97,
0.97))), sep = "")
package_result <- misclass(matrix(unlist(reported), nrow = 2),
type = "exposure",
bias_parms = c(0.75, 0.75, 0.97, 0.97))
cat(sprintf("episensr: odds ratio %.3f [%.3f, %.3f], risk ratio %.3f\n",
package_result$adj_measures[2, 1],
package_result$adj_measures[2, 2],
package_result$adj_measures[2, 3],
package_result$adj_measures[1, 1]))
smokers <- births[births$smoker == 1, ]
by_outcome <- tapply(smokers$reported_smoker, smokers$sga, mean)
cat(sprintf("Realized sensitivity: cases %.3f, non-cases %.3f\n",
by_outcome[["1"]], by_outcome[["0"]]))
scenarios <- list(
"Same in both groups" = c(0.75, 0.75, 0.97, 0.97),
"Cases recall more" = c(0.90, 0.75, 0.97, 0.97),
"Cases conceal more" = c(0.60, 0.75, 0.97, 0.97),
"Cases over-report" = c(0.75, 0.75, 0.90, 0.97),
"Worse than a coin" = c(0.30, 0.30, 0.60, 0.60)
)
cat(sprintf("%-20s %-11s %-11s %s\n", "Scenario", "Sensitivity",
"Specificity", "Expected RR"))
for (name in names(scenarios)) {
values <- scenarios[[name]]
expected <- MisclassifyExposure(source_population, values)
cat(sprintf("%-20s %.2f, %.2f %.2f, %.2f %11.2f\n", name, values[1],
values[2], values[3], values[4], RiskRatio(expected)))
}
Table a1 b1 a0 b0 OR RR [95% CI]
Reported smoking 248 1432 566 5754 1.761 1.648 [1.434, 1.895]
Corrected 311 1689 503 5497 2.007 1.850
episensr: odds ratio 2.007 [1.644, 2.449], risk ratio 1.850
Realized sensitivity: cases 0.737, non-cases 0.756
Scenario Sensitivity Specificity Expected RR
Same in both groups 0.75, 0.75 0.97, 0.97 1.75
Cases recall more 0.90, 0.75 0.97, 0.97 2.21
Cases conceal more 0.60, 0.75 0.97, 0.97 1.36
Cases over-report 0.75, 0.75 0.90, 0.97 2.06
Worse than a coin 0.30, 0.30 0.60, 0.60 0.94

Reported smoking gives a risk ratio of 1.648 with a 95% interval from 1.434 to 1.895, which excludes the true 2.0 and the full-cohort 1.937. The smokers who said no sit in the nonsmoker row and raise its risk, and the nonsmokers who said yes dilute the smoker row, so the two risks move toward each other.

The correction with the true sensitivity and specificity returns 1.850, and misclass() agrees. That is closer to 1.937 without reaching it, and the line on the realized sensitivity says why. The answers were random draws, and the realized sensitivity came out at 0.737 among cases and 0.756 among non-cases. The correction assumes 0.75 in both groups, so it undoes the expected misclassification and leaves the chance part in place. misclass() also gives an interval for the corrected odds ratio, 1.644 to 2.449, which treats the sensitivity and the specificity as known constants.

With the same error in both groups the expected risk ratio is 1.75, and the cohort’s 1.648 is one sample from that process. If cases report smoking more completely, 0.90 against 0.75, the expected ratio is 2.21, above the truth. If cases conceal it, 0.60 against 0.75, the ratio falls to 1.36. A lower specificity among cases, 0.90 against 0.97, gives 2.06. Differential error can push the estimate in either direction, and a change of 0.15 in one sensitivity moves it from 1.75 to 2.21 or to 1.36.

The rule that non-differential misclassification biases toward the null is narrower than its reputation. It is a statement about the expected estimate for an exposure with two levels, when the errors do not depend on errors in other variables and the measure is better than chance, so that Se + Sp exceeds 1. The last scenario breaks the final condition: the sum is 0.90 and the expected ratio is 0.94, on the far side of 1. With three or more exposure levels, the estimate for a middle level can move away from the null. An expectation is also no guarantee for one study, since the realized sensitivities above differed between cases and non-cases by chance alone. Do not write that non-differential misclassification made an estimate conservative.

The corrections so far used one value for each bias parameter, as if the sensitivity were known to be 0.75. It never is. Suppose a validation substudy compared self-report with cotinine in 80 smokers and 200 nonsmokers and found 60 and 194 correct answers. With a uniform prior those counts give a Beta(61, 21) distribution for the sensitivity and a Beta(195, 7) distribution for the specificity. A probabilistic bias analysis draws a pair of values from these distributions, corrects the table with them, and repeats 50,000 times. The spread of the corrected risk ratios, drawn as a histogram, is the uncertainty that comes from not knowing the two parameters.

That spread holds systematic error only. To add random error, the code also resamples the reported table for each draw, from a multinomial distribution with the observed cell proportions, and corrects the resampled table. A draw is impossible when it makes a corrected count negative: a specificity that implies more false positives than there are reported smokers, or a sensitivity too low for the number of smokers reported. The code counts those draws and drops them. In R, probsens() from episensr runs the analysis from the same two distributions, passed as seca and spca, and discards impossible draws as well.

set.seed(2026)
draws <- 50000
sensitivity <- rbeta(draws, 61, 21)
specificity <- rbeta(draws, 195, 7)
accuracy <- list(sensitivity, sensitivity, specificity, specificity)
systematic <- CorrectExposure(reported, accuracy)
resampled <- rmultinom(draws, nrow(births), unlist(reported) / nrow(births))
resampled <- list(a1 = resampled[1, ], b1 = resampled[2, ],
a0 = resampled[3, ], b0 = resampled[4, ])
total <- CorrectExposure(resampled, accuracy)
tables <- list("Systematic error" = systematic,
"Systematic and random error" = total)
corrected_rr <- list()
for (name in names(tables)) {
impossible <- do.call(pmin, tables[[name]]) <= 0
corrected_rr[[name]] <- RiskRatio(tables[[name]])[!impossible]
limits <- quantile(corrected_rr[[name]], c(0.5, 0.025, 0.975))
cat(sprintf("%-28s %d impossible, median %.3f [%.3f, %.3f]\n", name,
sum(impossible), limits[1], limits[2], limits[3]))
}
set.seed(2026)
package_rr <- probsens(matrix(unlist(reported), nrow = 2),
type = "exposure", reps = draws,
seca = list("beta", c(61, 21)),
spca = list("beta", c(195, 7)))$adj_measures
cat(sprintf("episensr, %-18s median %.3f [%.3f, %.3f]\n",
c("systematic error", "total error"), package_rr[1:2, 1],
package_rr[1:2, 2], package_rr[1:2, 3]), sep = "")
wide_specificity <- runif(draws, 0.70, 1)
wide <- CorrectExposure(reported, list(sensitivity, sensitivity,
wide_specificity, wide_specificity))
cat(sprintf("Uniform(0.70, 1) specificity: %d of %d draws impossible\n",
sum(do.call(pmin, wide) <= 0), draws))
plot_data <- stack(corrected_rr)
correction_plot <- ggplot(plot_data, aes(values, fill = ind)) +
geom_histogram(aes(y = after_stat(density)), binwidth = 0.02,
boundary = 1, position = "identity", alpha = 0.6) +
geom_vline(xintercept = reported_limits[["estimate"]],
linetype = "dashed") +
geom_vline(xintercept = 2) +
scale_fill_manual(values = c("#1f4e5f", "#e0a458"), name = NULL) +
coord_cartesian(xlim = c(1.3, 2.7)) +
labs(x = "Bias-corrected risk ratio (dashed: observed, solid: truth)",
y = "Density") +
theme_classic(base_size = 12) +
theme(legend.position = "top")
ggsave("outputs/bias-corrected-r.png", correction_plot, width = 6.5,
height = 4, dpi = 150)
Systematic error 0 impossible, median 1.871 [1.779, 2.034]
Systematic and random error 0 impossible, median 1.873 [1.558, 2.280]
episensr, systematic error median 1.871 [1.779, 2.034]
episensr, total error median 1.876 [1.575, 2.263]
Uniform(0.70, 1) specificity: 16721 of 50000 draws impossible

Two overlaid histograms of the bias-corrected risk ratio, drawn with ggplot2. The histogram for systematic error alone is narrow and peaks near 1.87. The histogram that adds random error is wider and runs from about 1.5 to 2.4. A dashed vertical line marks the observed risk ratio of 1.65 in the left tail of the wider histogram, and a solid line marks the truth at 2.0.

With these distributions no draw was impossible. The systematic error alone gives a median of 1.871 and a 95% simulation interval from 1.779 to 2.034 in R. Python uses a different random number generator and prints 2.036 for the upper limit. With random error added, the interval is 1.558 to 2.280 in R and 1.560 to 2.286 in Python. The conventional interval of the reported table, 1.434 to 1.895, excluded the truth. The bias-corrected interval is centered near 1.87, contains both the true 2.0 and the full-cohort 1.937, and is wider. Part of the extra width comes from the correction itself, which divides the random error by Se + Sp − 1, and part comes from admitting that the sensitivity and the specificity are not known.

probsens() called with the same seed draws the same sensitivities and specificities, so its systematic-error line matches the hand calculation to three decimals. Its total-error line, 1.575 to 2.263, comes from a different procedure, which samples the corrected cell counts for each draw and then adds a normal error.

The last line shows what an impossible draw is. In the reported table, 1,432 of the 7,186 non-cases said that they smoked, 19.9%, so the specificity cannot be below 0.801, or the false positives alone would outnumber them. A vaguer Uniform(0.70, 1) distribution puts a third of its draws under that floor: 16,721 of 50,000 in R and 16,768 in Python. Dropping them replaces the stated distribution with a truncated one, so the count belongs in the report.

The narrow histogram is the systematic error, narrow because 280 validated answers pin the two parameters down well. The wide histogram adds the random error. The observed 1.648 sits in its left tail, and the truth lies inside both. The correction moved toward the truth because the two distributions were centered on the sensitivity and specificity that the simulation used. Distributions centered elsewhere would give an equally smooth histogram around a wrong value, and nothing in the output would show it, so the source of each distribution is the part of a bias analysis that a reader has to be able to check.

Selection and misclassification have parameters that a validation study can estimate. An unmeasured confounder has none, since nobody measured it. The E-value turns the question around. It is the minimum strength of association, on the risk ratio scale, that an unmeasured confounder would need with both the exposure and the outcome, conditional on the measured covariates, to move the estimate to the null. For a risk ratio RR above 1 it equals RR + sqrt(RR × (RR − 1)); for a ratio below 1, take the reciprocal first. The same formula applied to the confidence limit nearest 1 gives the strength needed to move that limit to 1, and when the interval already contains 1 that E-value is 1.

The formula follows from a bound. For a confounder with two levels, let RREU be the ratio of its prevalence among the exposed to its prevalence among the unexposed, and RRUD the factor by which it multiplies the risk of the outcome. The confounder can inflate the risk ratio by at most RREU × RRUD / (RREU + RRUD − 1), and setting both associations to one value and the bound to the observed ratio gives the E-value. When the exposure has no effect, the risk in a group is the risk without the confounder times 1 + (RRUD − 1) × the share of the group that carries it, so the spurious risk ratio is the ratio of that quantity between smokers and nonsmokers. The code checks the bound with that formula and with a simulation of four million births in which smoking has no effect at all. In R, evalues.RR() from the EValue package returns both E-values.

#' Compute the E-value of a risk ratio above or below 1.
#'
#' @param rr A risk ratio.
#' @return The E-value.
EValueOf <- function(rr) {
rr <- max(rr, 1 / rr)
rr + sqrt(rr * (rr - 1))
}
e_point <- EValueOf(full_limits[["estimate"]])
e_limit <- 1
if (full_limits[["lower"]] > 1) e_limit <- EValueOf(full_limits[["lower"]])
cat(sprintf("Risk ratio %.3f, E-value %.3f; lower limit %.3f, E-value %.3f\n",
full_limits[["estimate"]], e_point, full_limits[["lower"]],
e_limit))
print(round(evalues.RR(full_limits[["estimate"]], full_limits[["lower"]],
full_limits[["upper"]]), 3))
cat(sprintf("Largest bias at %.3f and %.3f: %.3f\n", e_point, e_point,
e_point * e_point / (e_point + e_point - 1)))
for (share_smokers in c(1, 0.5)) {
share_nonsmokers <- share_smokers / e_point
spurious <- (1 + (e_point - 1) * share_smokers) /
(1 + (e_point - 1) * share_nonsmokers)
cat(sprintf("Confounder in %.3f of smokers, %.3f of nonsmokers: %.3f\n",
share_smokers, share_nonsmokers, spurious))
}
weaker <- 2 * 2 / (2 + 2 - 1)
cat(sprintf("Largest bias at 2 and 2: %.3f, which leaves %.3f\n", weaker,
full_limits[["estimate"]] / weaker))
set.seed(2026)
people <- 4000000
smoker_sim <- rbinom(people, 1, 0.25)
confounder <- rbinom(people, 1, ifelse(smoker_sim == 1, 1, 1 / e_point))
risk_without <- 0.08 / (1 + (e_point - 1) / e_point)
outcome_sim <- rbinom(people, 1,
risk_without * ifelse(confounder == 1, e_point, 1))
simulated <- CountCells(smoker_sim, outcome_sim)
cat(sprintf("Simulated, no effect of smoking: risks %.3f and %.3f, RR %.3f\n",
simulated$a1 / (simulated$a1 + simulated$b1),
simulated$a0 / (simulated$a0 + simulated$b0),
RiskRatio(simulated)))
Risk ratio 1.937, E-value 3.285; lower limit 1.699, E-value 2.788
point lower upper
RR 1.937 1.699 2.209
E-values 3.285 2.788 NA
Largest bias at 3.285 and 3.285: 1.937
Confounder in 1.000 of smokers, 0.304 of nonsmokers: 1.937
Confounder in 0.500 of smokers, 0.152 of nonsmokers: 1.590
Largest bias at 2 and 2: 1.333, which leaves 1.453
Simulated, no effect of smoking: risks 0.155 and 0.080, RR 1.937

The E-value of the estimate is 3.285 and the E-value of the lower limit is 2.788. evalues.RR() prints the same two numbers and NA for the upper limit, which is not the one nearest 1. To explain away a risk ratio of 1.937, an unmeasured confounder with equal strength on both sides would need a risk ratio of at least 3.285 with smoking and with a small-for-gestational-age birth. To move the lower confidence limit to 1, it would need 2.788 with both. A confounder weaker than that on both sides cannot do it, and a confounder with unequal strengths can do it only if the stronger side is above 3.285.

The check lines confirm the reading. With both associations at 3.285 the largest possible bias is 1.937, the estimate itself. That maximum is reached when every smoker carries the confounder and 30.4% of the nonsmokers do. In the simulated births with that arrangement smoking does nothing, the risks are 0.155 and 0.080, and the risk ratio is 1.937 in R and 1.934 in Python. Spread the same association differently, with the confounder in 50% of the smokers and 15.2% of the nonsmokers, and the spurious ratio is 1.590. A confounder at the E-value can explain the estimate, then, but only in its most unfavorable arrangement. A confounder with a risk ratio of 2 on both sides biases the estimate by at most 1.333 and would leave 1.453.

The E-value is not a probability. It says nothing about whether such a confounder exists, and that judgment needs knowledge of the field, since the same E-value is large where the known risk factors are weak and unremarkable where they are strong. A large E-value does not prove causation either. Smoking is causal in this table because the simulation assigned it at random, and no formula applied to four counts can show that. The E-value also covers confounding alone. Computed on the participants of the selection section, it would describe an estimate that selection had already biased.

Do not choose the bias parameters after seeing which ones rescue the result. In the scenario table, moving one sensitivity between 0.60 and 0.90 moved the expected ratio between 1.36 and 2.21, so an analyst who is free to pick can reach almost any answer. Fix each distribution and its source before the correction runs, and report every scenario that was run.

Do not treat a confounder measured with error as controlled. Adjustment for a confounder with non-differential misclassification removes only part of its confounding, so the adjusted estimate keeps residual confounding. An adjustment for smoking as the mothers of this cohort reported it would leave a quarter of the smokers in the nonsmoker stratum.

Do not report the E-value of the point estimate alone. The estimate here has 3.285 and its lower limit has 2.788, and the second number is the one that allows for sampling error. When the interval contains 1, the E-value of the limit is 1, whatever the point estimate gives.

Do not present one correction as the corrected answer. Each section here removed one bias with parameters that the simulation supplied. A real estimate carries several biases at once, with parameters that are themselves uncertain, and a bias-corrected interval reflects the biases that were modeled and no others.

The episensr package by Haine provides basic sensitivity analysis of epidemiological results, including the corrections for selection bias and misclassification and the probabilistic analysis on this page.

VanderWeele and Ding, 2017 introduce the E-value, which the EValue package computes, and recommend reporting it for the estimate and for the confidence limit closest to the null.

Ding and VanderWeele, 2016 derive the bounding factor for the bias from unmeasured confounding without assumptions about the confounder.

Fox, MacLehose, and Lash, 2021 wrote the textbook that the episensr documentation cites for its selection, misclassification and probabilistic bias analyses.

Jurek and colleagues, 2005 show that non-differential exposure misclassification does not guarantee an underestimate in a single study, with a simulation of how often the observed relative risk overestimates the true one.

Dosemeci, Wacholder, and Lubin, 1990 give examples in which non-differential misclassification of an exposure with several levels biases the odds ratio of an intermediate level away from the null.

Greenland, 1980 examines misclassification in analyses with a covariate and shows that misclassification of a confounder leads to a partial loss of the ability to control confounding.

The episensr documentation covers the other bias models of the package, among them outcome misclassification, a probabilistic analysis of selection bias with probsens_sel(), and unmeasured confounding with confounders().

The EValue package website documents E-values for odds ratios, hazard ratios and mean differences, which need a conversion to the risk ratio scale that this page did not use.

Lash and colleagues, 2014 describe good practices for quantitative bias analysis: when an analysis is worth doing, how to select the biases to model, how to assign values to the bias parameters, and how to present the result.

Ioannidis, Tan, and Blum, 2019 set out the limitations of the E-value and the ways in which it is misread.

The causal diagrams page shows how to find the confounders and the colliders that a bias analysis has to consider. The case-control page covers the design in which selection on the outcome is deliberate. The risk measures page covers the risk ratio, the odds ratio and their intervals.