Graphique d'estimation
Données brutes de deux groupes, avec la différence de moyennes et son IC à 95 % par bootstrap.

Le graphique d'estimation de Gardner–Altman place la taille d'effet, et non la valeur p, au centre. L'axe de gauche montre chaque observation des deux groupes ; l'axe flottant de droite est calé de sorte que son zéro coïncide avec la moyenne du groupe de référence. Sur cet axe, la distribution bootstrap de la différence de moyennes est tracée sous forme de demi-violon, avec l'estimation ponctuelle et son intervalle de confiance à 95 % représentés par un point et une barre. Les nombres d'interactions étant très asymétriques, la comparaison se fait sur une échelle log10 : une différence de 0,3 correspond à peu près au double d'interactions.
Le contexte est celui de Warin, Melchior et de Marcellis-Warin (2025, Journal of Medical Internet Research), sur l'engagement du public envers l'OMS sur X avant et après la COVID-19. Les chiffres sont ici simulés à des fins d'illustration — les interactions (mentions « j'aime », republications et réponses) par publication de l'OMS pour n = 100 publications, 50 avant et 50 après le début de la pandémie — et ne sont ni les données ni les résultats de l'article. L'IC à 95 % est un bootstrap corrigé du biais et accéléré (BCa) issu de scipy.stats.bootstrap, le sous-titre ajoute le test t de Welch (scipy.stats.ttest_ind), le trait vertical à côté de chaque nuée de points correspond à la moyenne du groupe ± 1 écart type, et la nuée provient de seaborn.swarmplot.
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 seaborn as sns
from scipy import stats
# Simulated data, set in the context of Warin, Melchior & de Marcellis-Warin (2025) [warin2025who]
# Data: log10 of engagements per WHO post, before and after the start of COVID-19
rng = np.random.default_rng(2025)
pre, post = rng.normal(2.6, 0.38, 50), rng.normal(3.15, 0.45, 50)
df = pd.DataFrame({"group": ["Pre-COVID"] * 50 + ["Post-COVID"] * 50,
"log_eng": np.r_[pre, post]})
# Mean difference with a BCa bootstrap 95% CI, and the bootstrap distribution
diff = lambda a, b, axis=-1: np.mean(b, axis=axis) - np.mean(a, axis=axis)
boot = stats.bootstrap((pre, post), diff, n_resamples=5000, method="BCa",
random_state=np.random.default_rng(1))
lo, hi = boot.confidence_interval
delta = post.mean() - pre.mean()
t = stats.ttest_ind(post, pre, equal_var=False)
# Manual layout (the long subtitle would otherwise squeeze the panels apart)
fig, (ax, ax2) = plt.subplots(1, 2, figsize=(8, 5.2), width_ratios=[2.2, 1], layout="none")
fig.subplots_adjust(wspace=0.12)
palette = ["#8E8E93", "#007AFF"]
sns.swarmplot(data=df, x="group", y="log_eng", hue="group", palette=palette, size=5,
order=["Pre-COVID", "Post-COVID"], hue_order=["Pre-COVID", "Post-COVID"],
legend=False, ax=ax)
for i, d in enumerate([pre, post]): # mean ± SD as a gapped line beside the swarm
m, s = d.mean(), d.std(ddof=1)
ax.vlines(i + 0.32, m - s, m + s, color="#3A3A3C", lw=1.5)
ax.scatter(i + 0.32, m, s=30, color="white", edgecolor="#3A3A3C", lw=1.5, zorder=3)
ax.set_xlabel("")
ax.set_ylabel("Engagements per post (log10 scale)")
ax.set_yticks([2, 2.5, 3, 3.5, 4], ["100", "316", "1,000", "3,162", "10,000"])
ax.set_xticks([0, 1], [f"Before COVID-19\n(n = {len(pre)} posts)",
f"After COVID-19\n(n = {len(post)} posts)"])
# Floating difference axis: zero aligned with the pre-COVID mean
ax.set_xlim(-0.55, 1.6)
ymin, ymax = ax.get_ylim()
ax2.set_ylim(ymin - pre.mean(), ymax - pre.mean())
ax2.axhline(0, color="#3A3A3C", lw=1)
ax2.axhline(delta, color="#3A3A3C", lw=1, ls=":")
ax.plot([0.32, 1.6], [pre.mean()] * 2, color="#3A3A3C", lw=0.8)
ax.plot([1.32, 1.6], [post.mean()] * 2, color="#3A3A3C", lw=0.8, ls=":")
v = ax2.violinplot(boot.bootstrap_distribution, positions=[0], widths=0.8,
showextrema=False, side="high")
v["bodies"][0].set(facecolor="#007AFF", alpha=0.3, edgecolor="none")
ax2.vlines(0, lo, hi, color="#1D1D1F", lw=2.5)
ax2.scatter(0, delta, s=70, color="#1D1D1F", zorder=3)
ax2.annotate(f"Δ = {delta:+.2f}\n[{lo:.2f}, {hi:.2f}]", (0, hi), xytext=(-6, 8),
textcoords="offset points", ha="right", va="bottom", fontsize=9.5,
fontweight="semibold", color="#007AFF")
ax2.set_xlim(-0.6, 0.6)
ax2.set_xticks([0], ["After − Before"])
ax2.yaxis.tick_right(); ax2.yaxis.set_label_position("right")
ax2.spines[["left"]].set_visible(False); ax2.spines["right"].set_visible(True)
ax2.set_ylabel("Mean difference (log10 engagements)")
ax2.grid(False)
ax.set_title(f"Post minus pre: a mean difference of {delta:+.2f} on the log10 scale, with its bootstrap CI",
pad=26)
ax.text(0, 1.02, f"n = {len(df)} posts (simulated) · BCa bootstrap 95% CI [{lo:.2f}, {hi:.2f}] · "
f"Welch's t({t.df:.1f}) = {t.statistic:.2f}, p = {t.pvalue:.1e}",
transform=ax.transAxes, fontsize=9.5, color="#6E6E73")
plt.show()
# Estimation plot: the R equivalent of plot.py
# Simulated data, set in the context of Warin, Melchior & de Marcellis-Warin (2025) [warin2025who]
# R and NumPy draw different random numbers, so the values differ slightly from the Python figure.
library(boot)
library(ggplot2)
set.seed(2025)
# Data: log10 of engagements per WHO post, before and after the start of COVID-19
pre <- rnorm(50, 2.6, 0.38)
post <- rnorm(50, 3.15, 0.45)
d <- data.frame(group = rep(c("pre", "post"), each = 50), x = rep(1:2, each = 50),
log_eng = c(pre, post))
# Mean difference with a BCa bootstrap 95% CI, and the bootstrap distribution
mean_diff <- function(data, i) {
b <- data[i, ]
mean(b$log_eng[b$group == "post"]) - mean(b$log_eng[b$group == "pre"])
}
bs <- boot(d, mean_diff, R = 5000, strata = factor(d$group)) # resample within each group
ci <- boot.ci(bs, type = "bca")$bca[4:5]
delta <- mean(post) - mean(pre)
tt <- t.test(post, pre) # Welch's t-test
# Mean ± SD of each group, drawn as a line beside its swarm
stats <- data.frame(x = 1:2 + 0.32, m = c(mean(pre), mean(post)), s = c(sd(pre), sd(post)))
# Bootstrap distribution as a half violin on the floating difference axis,
# whose zero sits at the pre-COVID mean
k <- density(bs$t)
violin <- data.frame(y = k$x + mean(pre), width = 0.45 * k$y / max(k$y))
p <- ggplot(d, aes(x, log_eng)) +
geom_dotplot(aes(group = group, fill = group), binaxis = "y", stackdir = "center",
binwidth = 0.045, colour = NA, show.legend = FALSE) +
scale_fill_manual(values = c(pre = "#8E8E93", post = "#007AFF")) +
geom_linerange(data = stats, aes(x = x, ymin = m - s, ymax = m + s), inherit.aes = FALSE,
colour = "#3A3A3C", linewidth = 0.7) +
geom_point(data = stats, aes(x, m), shape = 21, size = 2.2, fill = "white", colour = "#3A3A3C",
stroke = 0.8) +
# Reference lines from the group means to the difference axis
annotate("segment", x = 1.32, xend = 3.6, y = mean(pre), yend = mean(pre), colour = "#3A3A3C",
linewidth = 0.4) +
annotate("segment", x = 2.32, xend = 3.6, y = mean(post), yend = mean(post), colour = "#3A3A3C",
linewidth = 0.4, linetype = "dotted") +
# Difference: bootstrap distribution, 95% CI and point estimate
geom_ribbon(data = violin, aes(y = y, xmin = 3, xmax = 3 + width), inherit.aes = FALSE,
fill = "#007AFF", alpha = 0.3) +
annotate("linerange", x = 3, ymin = mean(pre) + ci[1], ymax = mean(pre) + ci[2],
colour = "#1D1D1F", linewidth = 1.2) +
annotate("point", x = 3, y = mean(post), size = 3.2, colour = "#1D1D1F") +
annotate("text", x = 2.95, y = mean(pre) + ci[2] + 0.04, hjust = 1, vjust = 0, lineheight = 0.95,
label = sprintf("Δ = %+.2f\n[%.2f, %.2f]", delta, ci[1], ci[2]), colour = "#007AFF",
fontface = "bold", size = 3.3) +
scale_x_continuous(breaks = 1:3, limits = c(0.45, 3.6), expand = c(0, 0),
labels = c(sprintf("Before COVID-19\n(n = %d posts)", length(pre)),
sprintf("After COVID-19\n(n = %d posts)", length(post)),
"After − Before")) +
scale_y_continuous(breaks = seq(2, 4, 0.5), labels = c("100", "316", "1,000", "3,162", "10,000"),
sec.axis = sec_axis(~ . - mean(pre), name = "Mean difference (log10 engagements)")) +
labs(title = sprintf("Post minus pre: a mean difference of %+.2f on the log10 scale, with its bootstrap CI",
delta),
subtitle = sprintf(paste("n = %d posts (simulated) · BCa bootstrap 95%% CI [%.2f, %.2f] ·",
"Welch's t(%.1f) = %.2f, p = %.1e"),
nrow(d), ci[1], ci[2], tt$parameter, tt$statistic, tt$p.value),
x = NULL, y = "Engagements per post (log10 scale)") +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(face = "bold", size = 11),
plot.title.position = "plot",
plot.subtitle = element_text(size = 8.5, colour = "#6E6E73"),
axis.text.x = element_text(colour = "#1D1D1F", size = 10),
panel.grid.minor = element_blank(), panel.grid.major.x = 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. - Warin, Melchior & de Marcellis-Warin (2025), public engagement with the WHO on X. Warin, T., Melchior, C., & de Marcellis-Warin, N. (2025). Social media metrics and popular legitimacy: Content analysis of pre- and post-COVID-19 public engagement with the WHO on X. Journal of Medical Internet Research, 27, e69959. https://doi.org/10.2196/69959
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). Estimation plot. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/group-comparisons/estimation-plot/
@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 Comparaisons de groupes
Comparaison entre groupes
Violon, boîte et points avec ANOVA de Welch, taille d'effet et tests deux à deux.
ggstatsplot::ggbetweenstats()Comparaison intra-sujets
Mesures répétées avec une ligne par sujet, moyennes, ANOVA à mesures répétées et tests appariés.
ggstatsplot::ggwithinstats()Graphique d'interaction
Moyennes de groupes avec intervalles de confiance à 95 % pour deux facteurs, avec ANOVA à deux facteurs.
ggpubr::ggline(add = "mean_ci") / ggstats