Data Science · Klinik Klinische Datenanalyse & Machine Learning
Ansicht
Lerntiefe
Codeansicht
Farbschema

21 · Auswahl der passenden statistischen Methode

dist_t_vs_mwu.png

Abbildung · Quellcode

dist_t_vs_mwu

Erzeugt im Abschnitt „MODULE 21 · Test selection guide (5 figures showing distributions)" in data/figures.py, Zeile 757–792.

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
# ===========================================================================
# MODULE 21 · Test selection guide (5 figures showing distributions)
# ===========================================================================
print("[21] Testwahl-Verteilungen ...")
M21_DIR = ASSETS / "21-statistik-entscheidung" / "assets"
M21_DIR.mkdir(parents=True, exist_ok=True)

# --- 1) Welch-t-Test vs. Mann-Whitney-U ---
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9.5, 4))
fig.subplots_adjust(wspace=0.35, bottom=0.18)

# Welch-t-Test: Two symmetric normal distributions
x = np.linspace(30, 110, 200)
ax1.plot(x, stats.norm.pdf(x, 65, 10), color=PRIMARY, linewidth=2, label="Gruppe A")
ax1.fill_between(x, stats.norm.pdf(x, 65, 10), alpha=0.15, color=PRIMARY)
ax1.plot(x, stats.norm.pdf(x, 75, 12), color=EVENT, linewidth=2, label="Gruppe B")
ax1.fill_between(x, stats.norm.pdf(x, 75, 12), alpha=0.15, color=EVENT)
ax1.set_title("t-Test / Welch-Test\n(Symmetrisch, Normalverteilt)")
ax1.set_xlabel("Messwert (z.B. Alter)")
ax1.set_ylabel("Dichte")
ax1.legend(loc="upper right")
ax1.grid(True, linestyle=":", alpha=0.6)

# Mann-Whitney-U: Two skewed distributions
x_skew = np.linspace(0, 12, 200)
ax2.plot(x_skew, stats.gamma.pdf(x_skew, 2, 0, 1), color=PRIMARY, linewidth=2, label="Gruppe A")
ax2.fill_between(x_skew, stats.gamma.pdf(x_skew, 2, 0, 1), alpha=0.15, color=PRIMARY)
ax2.plot(x_skew, stats.gamma.pdf(x_skew, 2, 0, 1.5), color=EVENT, linewidth=2, label="Gruppe B")
ax2.fill_between(x_skew, stats.gamma.pdf(x_skew, 2, 0, 1.5), alpha=0.15, color=EVENT)
ax2.set_title("Mann-Whitney-U-Test\n(Schief / Nicht-normalverteilt / Ordinal)")
ax2.set_xlabel("Messwert (z.B. Laktat, Liegedauer)")
ax2.set_ylabel("Dichte")
ax2.legend(loc="upper right")
ax2.grid(True, linestyle=":", alpha=0.6)

save(fig, M21_DIR / "dist_t_vs_mwu.png")

← zurück zu Modul 21 · vollständige Datei ansehen