21 · Auswahl der passenden statistischen Methode
dist_paired_t_vs_wilcoxon.png
Abbildung · Quellcode

Erzeugt im Abschnitt „dist_paired_t_vs_wilcoxon“ in data/figures.py, Zeile 717–744.
Dieses Skript läuft von oben nach unten. Der gemeinsame Vorspann – Bibliotheken, Kohorte laden, Plot-Stil – steht am Anfang der vollständigen Datei und gilt für alle Abbildungen darin.
Python
Python-Code: in eine Datei mit Endung
.py schreiben und mit dem ▶-Knopf in VS Code ausführen – oder Zeile für Zeile in die Python-Konsole. Setzt die in Modul 02 eingerichtete Umgebung voraus.# --- 2) Paired t-Test vs. Wilcoxon Signed-Rank vs. sign test --- # One panel per estimand: mean difference (t), pseudo-median under a symmetric # difference distribution (signed-rank), median difference without symmetry # (sign test). The signed-rank test is NOT the answer to skewed differences. fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(13, 4)) fig.subplots_adjust(wspace=0.35, bottom=0.18) x = np.linspace(-15, 15, 300) panels = [ (ax1, stats.norm.pdf(x, -2, 4), "Gepaarter t-Test\n(mittlere Differenz)", "Differenz (z.B. Blutdruck-Änderung)"), (ax2, stats.t.pdf((x + 2) / 2.5, 2) / 2.5, "Wilcoxon-Vorzeichen-Rang\n(symmetrisch, schwere Ränder)", "Differenz (z.B. Blutdruck-Änderung)"), (ax3, stats.lognorm.pdf(x + 6, 0.6, scale=5), "Vorzeichentest / Bootstrap\n(schief: Median der Differenzen)", "Differenz (z.B. CRP-Änderung)"), ] for ax, density, title, xlabel in panels: ax.plot(x, density, color=PRIMARY, linewidth=2, label="Differenzen (D3 - D0)") ax.fill_between(x, density, alpha=0.15, color=PRIMARY) ax.axvline(0, color=SECONDARY, linestyle="--", linewidth=1.2) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel("Dichte") # Extra headroom above the curve so the legend never crosses the peak. ax.set_ylim(0, ax.get_ylim()[1] * 1.32) ax.legend(loc="upper right") ax.grid(True, linestyle=":", alpha=0.6) save(fig, M21_DIR / "dist_paired_t_vs_wilcoxon.png")