Marginal
Showing and telling
Advice
Intermediate
Has two opposite meanings: in statistics, it’s the integral; in economics, it’s the derivative.
What it is
“Marginal” means opposite things in two neighboring fields:
- In statistics, a marginal distribution or probability integrates out other variables: \(p(y) = \int p(y \mid x)\,p(x)\,dx\). The name comes from totals written in the margins of a table.
- In economics, a marginal effect or cost is a derivative: the change in output for a small change in input, \(\partial\,\mathrm{E}(y \mid x)/\partial x\).
One is an average over everything, the other an instantaneous rate at a point.
Why it matters
Cross-disciplinary work, such as causal inference, econometrics and applied regression, is full of this collision. “Marginal effects” in a logistic regression (economics sense) are not “marginal probabilities” (statistics sense), and software uses both terms. Confusing them leads to misreported results: an average predicted probability reported as an effect, or a derivative at the mean reported as a population average.
How it works
For a logistic regression \(\Pr(y = 1 \mid x) = \text{logit}^{-1}(a + bx)\) with \(x \sim \mathrm{N}(\mu_x, \sigma_x)\):
- Statistics’ marginal: \(\Pr(y = 1) = \mathrm{E}_x[\text{logit}^{-1}(a + bx)]\), averaged over the distribution of \(x\).
- Economics’ marginal: \(\frac{d}{dx}\text{logit}^{-1}(a + bx) = b\,p(1-p)\), a slope that is different at every \(x\). The “average marginal effect” averages this over \(x\).
Simulated example
A logistic curve with a distribution of \(x\) underneath. Pick a point and compare the two “marginals.”
Show simulation code
The R version uses base R, and the Python version uses NumPy and Matplotlib. Where the simulation draws random numbers, each language draws its own, so exact numbers differ slightly but show the same pattern. The numbered markers in the R code are explained under it.
import {rng, range, mean, invLogit, fmt} from "../js/stats.js"
viewof b = Inputs.range([0.2, 3], {value: 1.2, step: 0.1, label: "Slope b (log-odds per unit x)"})
viewof x0 = Inputs.range([-3, 3], {value: 0.5, step: 0.1, label: "Point x₀ for the derivative"})
viewof seed = Inputs.range([1, 500], {value: 126, step: 1, label: "Random seed"})
marg = {
const r = rng(seed);
const a = -0.5, xs = r.normals(5000, 0.3, 1);
const p = x => invLogit(a + b * x);
const p0 = p(x0), slope = b * p0 * (1 - p0);
return {
curve: range(121).map(i => { const x = -4 + i / 15; return {x, p: p(x)}; }),
xs: xs.slice(0, 800), p0, slope,
statMarginal: mean(xs.map(p)),
ame: mean(xs.map(x => b * p(x) * (1 - p(x)))),
tangent: [-1, 1].map(dx => ({x: x0 + dx, p: p0 + slope * dx}))
};
}
Plot.plot({
ariaLabel: "Marginal: simulation chart",
ariaDescription: "Horizontal axis: x. Vertical axis: Pr(y = 1). The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 320,
x: {label: "x", domain: [-4, 4], grid: true},
y: {label: "Pr(y = 1)", domain: [-0.05, 1], grid: true},
marks: [
Plot.tickX(marg.xs, {x: d => d, y: () => -0.03, stroke: "#8a8a8a", strokeOpacity: 0.2}),
Plot.line(marg.curve, {x: "x", y: "p", stroke: "currentColor", strokeWidth: 2}),
Plot.ruleY([marg.statMarginal], {stroke: "#2166ac", strokeWidth: 2, strokeDasharray: "6 3"}),
Plot.line(marg.tangent, {x: "x", y: "p", stroke: "#d6604d", strokeWidth: 3}),
Plot.dot([{x: x0, p: marg.p0}], {x: "x", y: "p", r: 5, fill: "#d6604d"})
]
})# Marginal: an integral in statistics, a derivative in economics.
1b <- 1.2 # slope (log-odds per unit x)
x0 <- 0.5 # point for the derivative
2set.seed(126)
a <- -0.5
x <- rnorm(5000, 0.3, 1) # the distribution of x
p <- function(x) plogis(a + b * x)
3stat_marginal <- mean(p(x)) # Pr(y = 1), averaging over x
4slope <- b * p(x0) * (1 - p(x0)) # dPr/dx at x0
5ame <- mean(b * p(x) * (1 - p(x))) # average marginal effect
cat("Statistics' marginal: Pr(y = 1) =", round(stat_marginal, 3), "\n")
cat("Economics' marginal at x0:", round(slope, 3), "per unit x\n")
cat("Average marginal effect over x:", round(ame, 3), "\n")
6curve(p, -4, 4,
lwd = 2, col = "#2166ac", xlab = "x", ylab = "Pr(y = 1)",
ylim = c(0, 1)
)
abline(h = stat_marginal, col = "#2166ac", lty = 2)
segments(x0 - 1, p(x0) - slope, x0 + 1, p(x0) + slope,
col = "#d6604d",
lwd = 2
)
rug(x[1:800], col = "grey60")- 1
- The page’s controls: the slope of the logistic model and the point at which to take the derivative.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- The statistician’s marginal: the probability of y = 1 averaged (integrated) over the distribution of x.
- 4
- The economist’s marginal: the derivative of the probability with respect to x, at one point.
- 5
- The average marginal effect, which averages the derivative over x.
- 6
- The logistic curve with both marginals: the dashed horizontal line is the integral, the red tangent is the derivative.
# Marginal: an integral in statistics, a derivative in economics.
import numpy as np
import matplotlib.pyplot as plt
b = 1.2 # slope (log-odds per unit x)
x0 = 0.5 # point for the derivative
rng = np.random.default_rng(126)
a = -0.5
x = rng.normal(0.3, 1, 5000) # the distribution of x
def p(v):
return 1 / (1 + np.exp(-(a + b * v)))
stat_marginal = p(x).mean() # Pr(y = 1), averaging over x
slope = b * p(x0) * (1 - p(x0)) # dPr/dx at x0
ame = np.mean(b * p(x) * (1 - p(x))) # average marginal effect
print(f"Statistics' marginal: Pr(y = 1) = {stat_marginal:.3f}")
print(f"Economics' marginal at x0: {slope:.3f} per unit x")
print(f"Average marginal effect over x: {ame:.3f}")
xs = np.linspace(-4, 4, 200)
plt.plot(xs, p(xs), color="#2166ac", linewidth=2)
plt.axhline(stat_marginal, color="#2166ac", linestyle="--")
plt.plot([x0 - 1, x0 + 1], [p(x0) - slope, p(x0) + slope],
color="#d6604d", linewidth=2)
plt.plot(x[:800], np.zeros(800), "|", color="0.6")
plt.ylim(-0.02, 1)
plt.xlabel("x")
plt.ylabel("Pr(y = 1)")
plt.show()Key takeaways
- In statistics, “marginal” means integrated over. In economics, it means derivative of.
- Say which one you mean, especially in interdisciplinary work.
- Marginal effects in nonlinear models vary with x. Report where they’re evaluated, or average them.
Source
- Andrew Gelman, Marginal and marginal (2006).