Graphique en forêt des rapports de cotes
Rapports de cotes d'une régression logistique sur échelle logarithmique, accompagnés d'un tableau RC [IC à 95 %].

Les coefficients logistiques sont des log-cotes ; une fois exponentiés, ils deviennent des rapports de cotes. Chaque point est la variation multiplicative de la cote de l'événement pour une variation d'une unité du prédicteur, le segment est son intervalle de confiance à 95 %, et la ligne en tirets à RC = 1 signifie « aucun effet ». Comme les rapports sont symétriques sur une échelle logarithmique (0,5 est aussi fort que 2), l'axe des x est logarithmique. La colonne de droite reprend les valeurs, comme le tableau d'un article.
Le contexte est celui de Blakely & Warin (2012, Global Economy Journal) : choix ou mimétisme dans la décision d'émigrer en Europe. Les données sont simulées à des fins d'illustration — ce ne sont ni les données ni les résultats de l'article : n = 2 500 répondants à une enquête, et la variable réponse indique s'ils ont l'intention de partir à l'étranger. Les prédicteurs sont l'âge, un diplôme du supérieur, le chômage, le fait d'avoir de la famille ou des amis à l'étranger et la satisfaction de vie. Le modèle est ajusté avec smf.logit() et les rapports de cotes sont les np.exp() de params et de conf_int().
Le code et le texte à l'intérieur des figures sont en anglais.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf
from matplotlib.ticker import FixedLocator, NullLocator
# Simulated data, set in the context of Blakely & Warin (2012) [blakely2012]
# Data: 2,500 respondents; intention to migrate from a known logistic model
rng = np.random.default_rng(2012)
n = 2500
df = pd.DataFrame({"age10": rng.uniform(1.8, 6.5, n), "tertiary": rng.binomial(1, 0.3, n),
"unemployed": rng.binomial(1, 0.1, n), "network": rng.binomial(1, 0.35, n),
"satisfaction": rng.integers(1, 11, n)})
eta = (-0.2 - 0.45 * df.age10 + 0.35 * df.tertiary + 0.7 * df.unemployed
+ 0.95 * df.network - 0.12 * df.satisfaction)
df["migrate"] = rng.binomial(1, 1 / (1 + np.exp(-eta)))
model = smf.logit("migrate ~ age10 + tertiary + unemployed + network + satisfaction",
data=df).fit(disp=False)
# Odds ratios with 95% CI (intercept dropped), sorted by effect
tab = np.exp(model.conf_int().drop("Intercept")).rename(columns={0: "low", 1: "high"})
tab = tab.assign(OR=np.exp(model.params), p=model.pvalues).sort_values("OR")
labels = {"age10": "Age (per 10 years)", "tertiary": "Tertiary education",
"unemployed": "Unemployed", "network": "Family/friends abroad",
"satisfaction": "Life satisfaction (1–10)"}
fig, ax = plt.subplots(figsize=(8.6, 4.6))
y = np.arange(len(tab))
colors = np.where(tab["p"] < 0.05, np.where(tab["OR"] > 1, "#FF9500", "#007AFF"), "#AEAEB2")
ax.axvline(1, color="#8E8E93", lw=1, ls="--", zorder=1)
ax.hlines(y, tab["low"], tab["high"], color=colors, lw=2.5, zorder=2)
ax.scatter(tab["OR"], y, s=80, marker="s", color=colors, edgecolor="white", lw=1.5, zorder=3)
# Right-hand "table" column: OR [95% CI] and p-value
tr = ax.get_yaxis_transform()
top = len(tab) - 0.15
ax.text(1.04, top, "OR [95% CI]", transform=tr, fontsize=10, fontweight="semibold")
ax.text(1.40, top, "p", transform=tr, fontsize=10, fontweight="semibold")
for yi, (_, r) in zip(y, tab.iterrows()):
ax.text(1.04, yi, f"{r.OR:.2f} [{r.low:.2f}, {r.high:.2f}]", transform=tr,
va="center", fontsize=10, color="#3A3A3C", family="monospace")
ax.text(1.40, yi, "<.001" if r.p < .001 else f"{r.p:.3f}".lstrip("0"), transform=tr,
va="center", fontsize=10, color="#3A3A3C", family="monospace")
ax.set_xscale("log")
ticks = [0.5, 0.67, 1, 1.5, 2, 3]
ax.xaxis.set_major_locator(FixedLocator(ticks))
ax.xaxis.set_minor_locator(NullLocator())
ax.set_xticklabels([f"{t:g}" for t in ticks])
ax.set_xlim(0.45, 3.9)
ax.set_yticks(y, [labels[t] for t in tab.index])
ax.set_ylim(-1.2, len(tab) + 0.1)
ax.grid(axis="x"); ax.grid(axis="y", visible=False)
ax.set_xlabel("Odds ratio of intending to migrate (log scale)")
# Direction hints along the bottom of the panel
for x0, x1, txt, c in [(0.95, 0.75, "lower odds", "#007AFF"), (1.05, 1.33, "higher odds", "#FF9500")]:
ax.annotate("", (x1, -0.85), (x0, -0.85), arrowprops=dict(arrowstyle="-|>", color=c, lw=1.2))
ax.text(x1 * (0.97 if x1 < 1 else 1.03), -0.85, txt, color=c, fontsize=9, va="center",
ha="right" if x1 < 1 else "left")
ax.set_title("Family or friends abroad more than double the odds of planning to move", pad=26)
ax.text(0, 1.02, f"Logistic regression · n = {int(model.nobs):,} respondents (simulated) · "
f"McFadden pseudo-R² = {model.prsquared:.3f} · LR χ²({model.df_model:.0f}) = "
f"{model.llr:.0f}, p < .001", transform=ax.transAxes, fontsize=9.5, color="#6E6E73")
plt.show()
# Odds-ratio forest plot: the R equivalent of plot.py
# Simulated data, set in the context of Blakely & Warin (2012) [blakely2012]
# R and NumPy draw different random numbers, so the values differ slightly from the Python figure.
library(ggplot2)
set.seed(2012)
# Data: 2,500 respondents; intention to migrate from a known logistic model
n <- 2500
df <- data.frame(age10 = runif(n, 1.8, 6.5), tertiary = rbinom(n, 1, 0.3),
unemployed = rbinom(n, 1, 0.1), network = rbinom(n, 1, 0.35),
satisfaction = sample(1:10, n, replace = TRUE))
eta <- with(df, -0.2 - 0.45 * age10 + 0.35 * tertiary + 0.7 * unemployed
+ 0.95 * network - 0.12 * satisfaction)
df$migrate <- rbinom(n, 1, plogis(eta))
model <- glm(migrate ~ age10 + tertiary + unemployed + network + satisfaction,
family = binomial, data = df)
# Odds ratios with Wald 95% CI (intercept dropped), sorted by effect
# (ggstats is not installed: exp() of coef() and confint.default() do what ggcoef_model() does)
ci <- exp(confint.default(model))[-1, ]
tab <- data.frame(term = rownames(ci), OR = exp(coef(model))[-1], low = ci[, 1], high = ci[, 2],
p = summary(model)$coefficients[-1, 4])
labels <- c(age10 = "Age (per 10 years)", tertiary = "Tertiary education",
unemployed = "Unemployed", network = "Family/friends abroad",
satisfaction = "Life satisfaction (1–10)")
tab <- tab[order(tab$OR), ]
tab$y <- seq_len(nrow(tab))
tab$colour <- ifelse(tab$p < 0.05, ifelse(tab$OR > 1, "#FF9500", "#007AFF"), "#AEAEB2")
tab$ci_txt <- sprintf("%.2f [%.2f, %.2f]", tab$OR, tab$low, tab$high)
tab$p_txt <- ifelse(tab$p < .001, "<.001", sub("^0", "", sprintf("%.3f", tab$p)))
# Model fit: McFadden pseudo-R² and the likelihood-ratio test against the null model
r2 <- 1 - model$deviance / model$null.deviance
lr <- model$null.deviance - model$deviance
lr_df <- model$df.null - model$df.residual
lr_p <- pchisq(lr, lr_df, lower.tail = FALSE)
# The "table" column sits to the right of the data, on the same log axis
x_ci <- 4.4; x_p <- 10.5
k <- nrow(tab)
p <- ggplot(tab, aes(OR, y)) +
geom_vline(xintercept = 1, colour = "#8E8E93", linewidth = 0.5, linetype = "dashed") +
geom_linerange(aes(xmin = low, xmax = high, colour = colour), linewidth = 1.2) +
geom_point(aes(fill = colour), shape = 22, size = 3.8, colour = "white", stroke = 1) +
scale_colour_identity() + scale_fill_identity() +
annotate("text", x = c(x_ci, x_p), y = k + 0.85, label = c("OR [95% CI]", "p"), hjust = 0,
size = 3.5, fontface = "bold", colour = "#1D1D1F") +
geom_text(aes(x = x_ci, label = ci_txt), hjust = 0, size = 3.4, family = "mono",
colour = "#3A3A3C") +
geom_text(aes(x = x_p, label = p_txt), hjust = 0, size = 3.4, family = "mono",
colour = "#3A3A3C") +
# Direction hints along the bottom of the panel
annotate("segment", x = c(0.95, 1.05), xend = c(0.75, 1.33), y = 0.15, yend = 0.15,
colour = c("#007AFF", "#FF9500"), linewidth = 0.5,
arrow = arrow(length = unit(0.08, "in"), type = "closed")) +
annotate("text", x = c(0.75 * 0.97, 1.33 * 1.03), y = 0.15, label = c("lower odds", "higher odds"),
hjust = c(1, 0), size = 3.1, colour = c("#007AFF", "#FF9500")) +
scale_x_log10(breaks = c(0.5, 0.67, 1, 1.5, 2, 3), labels = c("0.5", "0.67", "1", "1.5", "2", "3"),
limits = c(0.45, 15), expand = c(0, 0)) +
scale_y_continuous(breaks = tab$y, labels = labels[tab$term], limits = c(-0.2, k + 1.1),
expand = c(0, 0)) +
labs(title = "Family or friends abroad more than double the odds of planning to move",
subtitle = sprintf("Logistic regression · n = %s respondents (simulated) · McFadden pseudo-R² = %.3f · LR χ²(%d) = %.0f, %s",
format(nobs(model), big.mark = ","), r2, lr_df, lr,
if (lr_p < .001) "p < .001" else sprintf("p = %.3f", lr_p)),
x = "Odds ratio of intending to migrate (log scale)", y = NULL) +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(face = "bold"),
plot.title.position = "plot",
plot.subtitle = element_text(size = 8.5, colour = "#6E6E73"),
axis.text.y = element_text(colour = "#1D1D1F", size = 10),
axis.title.x = element_text(hjust = 0.2),
panel.grid.minor = element_blank(), panel.grid.major.y = element_blank())
print(p)
Les figures utilisent le style PyStatlas (facultatif) : ajoutez plt.style.use("pystatlas.mplstyle") pour obtenir exactement le même rendu.
Source des données
- Simulated data. Simulated data with a fixed random seed, created for this example.
No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work. - Blakely & Warin (2012), the decision to migrate in Europe. Blakely, A., & Warin, T. (2012). Choice or mimetism in the decision to migrate? A European illustration. Global Economy Journal, 12(2). https://doi.org/10.1515/1524-5861.1818
The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.
Les exemples illustrent des méthodes statistiques. Leurs chiffres sont simulés, sauf mention contraire dans l'entrée, et leurs titres décrivent ce que chaque figure montre dans ces données simulées — ni les résultats des articles cités, ni la position de l'auteur sur la question de fond. Pour les résultats, le contexte et les données, reportez-vous aux articles cités ici.
Comment citer
PyStatlas est créé et maintenu par Thierry Warin. S'il vous a été utile dans vos travaux, merci de le citer.
Warin, T. (2026). Odds-ratio forest plot. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/regression-models/odds-ratio-forest/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
version = {1.1.0},
howpublished = {\url{https://warin.ca/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}Plus dans Modèles de régression
Graphique des coefficients
Estimations de régression avec intervalles de confiance à 95 %, une ligne par terme.
ggstats::ggcoef_model()Comparaison de modèles emboîtés
Coefficients de trois régressions emboîtées de l'IDE côte à côte, pour voir comment les estimations bougent quand un bloc UE est ajouté.
ggstats::ggcoef_compare()Probabilités prédites
Courbes de probabilité issues du modèle, avec rubans d'IC à 95 %, selon un prédicteur et par groupe.
ggeffects::ggpredict() / marginaleffects::plot_predictions()