From a70ca12fe34e0cb0c149e18867d0c8319acde24d Mon Sep 17 00:00:00 2001 From: Johannes Keyser <johannes.keyser@sport.uni-giessen.de> Date: Mon, 25 Mar 2024 19:22:07 +0100 Subject: [PATCH] Korrektur 01, nun geht Export nach PDF und HTML --- Module/Modul_01.Rmd | 16 ++--- Module/Modul_01.ipynb | 154 +++++++++++++++++++++++------------------- 2 files changed, 91 insertions(+), 79 deletions(-) diff --git a/Module/Modul_01.Rmd b/Module/Modul_01.Rmd index 0300def..b79b938 100644 --- a/Module/Modul_01.Rmd +++ b/Module/Modul_01.Rmd @@ -92,19 +92,19 @@ zu definieren. Wenn Sie vor der Entscheidung stehen: *Nehme ich an der Schulung teil?* gibt es für Ihr Gehalt zwei **potenzielle Ergebnisse (englisch: Potential Outcomes)**: -- ${\color{blue}\text{Gehalt}}$ ohne ${\color{DarkGreen}\text{Schulung}}$: $\color{blue}{Y}^{\color{DarkGreen}{X=0}}$ +- $\color{blue}{\text{Gehalt}}$ ohne $\color{DarkGreen}{\text{Schulung}}$: $\color{blue}{Y}^{\color{DarkGreen}{X=0}}$ -- ${\color{blue}\text{Gehalt}}$ mit ${\color{DarkGreen}\text{Schulung}}$: $\color{blue}{Y}^{\color{DarkGreen}{X=1}}$ +- $\color{blue}{\text{Gehalt}}$ mit $\color{DarkGreen}{\text{Schulung}}$: $\color{blue}{Y}^{\color{DarkGreen}{X=1}}$ -$\color{blue}{Y}$ ist die *Wirkung*, das Ergebnis, also hier das ${\color{blue}\text{Gehalt}}$. +$\color{blue}{Y}$ ist die *Wirkung*, das Ergebnis, also hier das $\color{blue}{\text{Gehalt}}$. Das hochgestellte $\color{DarkGreen}{X}$ soll symbolisieren für welche Wert der *Ursache* das Ergebnis betrachtet wird. -Ohne ${\color{DarkGreen}\text{Schulung}}$ nimmt $\color{DarkGreen}{X}$ den Wert 0 an, mit ${\color{DarkGreen}\text{Schulung}}$ den Wert 1. +Ohne $\color{DarkGreen}{\text{Schulung}}$ nimmt $\color{DarkGreen}{X}$ den Wert 0 an, mit $\color{DarkGreen}{\text{Schulung}}$ den Wert 1. {width="65%"} ## -Der **individuelle kausale Effekt** $\color{orange}{\Delta}_i$ (griechisch: Delta) der Schulung ergibt sich dann als die Differenz zwischen diesen beiden potenziellen Ergebnissen: +Der **individuelle kausale Effekt** ${\color{orange}{\Delta}}_i$ (griechisch: Delta) der Schulung ergibt sich dann als die Differenz zwischen diesen beiden potenziellen Ergebnissen: $${\color{orange}{\Delta}}_i = {\color{blue}{Y}}_{i}^{{\color{DarkGreen}{X=1}}} - {\color{blue}{Y}}_{i}^{{\color{DarkGreen}{X=0}}}$$ @@ -112,9 +112,9 @@ Wobei - $i$ für die einzelne Beobachtung, hier die einzelne Person, steht; -- ${\color{blue}{Y}}_i$ für das ${\color{blue}\text{Gehalt}}$ von $i$; +- ${\color{blue}{Y}}_i$ für das $\color{blue}{\text{Gehalt}}$ von $i$; -- $\color{DarkGreen}{X}$ für die Teilnahme an der ${\color{DarkGreen}\text{Schulung}}$; dabei ist $\color{DarkGreen}{X_i=1}$ wenn $i$ teilnimmt und $\color{DarkGreen}{X_i=0}$ wenn $i$ nicht teilnimmt. +- $\color{DarkGreen}{X}$ für die Teilnahme an der $\color{DarkGreen}{\text{Schulung}}$; dabei ist $\color{DarkGreen}{X_i=1}$ wenn $i$ teilnimmt und $\color{DarkGreen}{X_i=0}$ wenn $i$ nicht teilnimmt. ## Ein fiktives Beispiel @@ -194,7 +194,7 @@ Sie sehen: häufig sind die individuellen kausalen Effekte positiv – sie k Das fundamentale Problem der kausalen Inferenz ist, dass wir den individuellen kausalen Effekt ${\color{orange}{\Delta}}_i = {\color{blue}{Y}}_{i}^{{\color{DarkGreen}{X=1}}} - {\color{blue}{Y}}_{i}^{{\color{DarkGreen}{X=0}}}$ **nicht** beobachten können. Es liegt je Beobachtung $i$ immer nur eines der beiden Potential Outcomes vor: -Entweder $\color{blue}{Y}^{\color{DarkGreen}{X=1}}$ ($\color{blue}\text{Gehalt}$ mit $\color{DarkGreen}\text{Schulung}$) **oder** $\color{blue}{Y}^{\color{DarkGreen}{X=0}}$ ($\color{blue}\text{Gehalt}$ ohne $\color{DarkGreen}\text{Schulung}$). +Entweder $\color{blue}{Y}^{\color{DarkGreen}{X=1}}$ ($\color{blue}{\text{Gehalt}}$ mit $\color{DarkGreen}{\text{Schulung}}$) **oder** $\color{blue}{Y}^{\color{DarkGreen}{X=0}}$ ($\color{blue}{\text{Gehalt}}$ ohne $\color{DarkGreen}{\text{Schulung}}$). - Wenn Person $i$ an der Schulung teilnimmt, liegt uns das Gehalt mit Schulung vor, ${\color{blue}{Y}}_{i}^{{\color{DarkGreen}{X=1}}}$, und nicht ${\color{blue}{Y}}_{i}^{{\color{DarkGreen}{X=0}}}$ diff --git a/Module/Modul_01.ipynb b/Module/Modul_01.ipynb index 3658abb..c462b3a 100644 --- a/Module/Modul_01.ipynb +++ b/Module/Modul_01.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "raw", - "id": "615d6c50", + "id": "b48cd639", "metadata": {}, "source": [ "---\n", @@ -19,7 +19,7 @@ }, { "cell_type": "markdown", - "id": "3c8c56a9", + "id": "05eac55c", "metadata": {}, "source": [ "<a href=\"https://ki-campus.org/\">\n", @@ -30,7 +30,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "a65669bf", + "id": "ad507c4c", "metadata": { "name": "setup", "tags": [ @@ -77,7 +77,7 @@ }, { "cell_type": "markdown", - "id": "a45240ca", + "id": "1b75d1e1", "metadata": {}, "source": [ "## Lernziele\n", @@ -116,7 +116,7 @@ }, { "cell_type": "markdown", - "id": "b4bc5d1d", + "id": "7e8cc203", "metadata": {}, "source": [ "Eine andere Möglichkeit ist es, diesen Effekt als \n", @@ -127,19 +127,19 @@ "\n", "Wenn Sie vor der Entscheidung stehen: *Nehme ich an der Schulung teil?* gibt es für Ihr Gehalt zwei **potenzielle Ergebnisse (englisch: Potential Outcomes)**:\n", "\n", - "- ${\\color{blue}\\text{Gehalt}}$ ohne ${\\color{DarkGreen}\\text{Schulung}}$: $\\color{blue}{Y}^{\\color{DarkGreen}{X=0}}$\n", + "- $\\color{blue}{\\text{Gehalt}}$ ohne $\\color{DarkGreen}{\\text{Schulung}}$: $\\color{blue}{Y}^{\\color{DarkGreen}{X=0}}$\n", "\n", - "- ${\\color{blue}\\text{Gehalt}}$ mit ${\\color{DarkGreen}\\text{Schulung}}$: $\\color{blue}{Y}^{\\color{DarkGreen}{X=1}}$\n", + "- $\\color{blue}{\\text{Gehalt}}$ mit $\\color{DarkGreen}{\\text{Schulung}}$: $\\color{blue}{Y}^{\\color{DarkGreen}{X=1}}$\n", "\n", - "$\\color{blue}{Y}$ ist die *Wirkung*, das Ergebnis, also hier das ${\\color{blue}\\text{Gehalt}}$.\n", + "$\\color{blue}{Y}$ ist die *Wirkung*, das Ergebnis, also hier das $\\color{blue}{\\text{Gehalt}}$.\n", "Das hochgestellte $\\color{DarkGreen}{X}$ soll symbolisieren für welche Wert der *Ursache* das Ergebnis betrachtet wird.\n", - "Ohne ${\\color{DarkGreen}\\text{Schulung}}$ nimmt $\\color{DarkGreen}{X}$ den Wert 0 an, mit ${\\color{DarkGreen}\\text{Schulung}}$ den Wert 1.\n", + "Ohne $\\color{DarkGreen}{\\text{Schulung}}$ nimmt $\\color{DarkGreen}{X}$ den Wert 0 an, mit $\\color{DarkGreen}{\\text{Schulung}}$ den Wert 1.\n", "\n", "{width=\"65%\"}\n", "\n", "##\n", "\n", - "Der **individuelle kausale Effekt** $\\color{orange}{\\Delta}_i$ (griechisch: Delta) der Schulung ergibt sich dann als die Differenz zwischen diesen beiden potenziellen Ergebnissen:\n", + "Der **individuelle kausale Effekt** ${\\color{orange}{\\Delta}}_i$ (griechisch: Delta) der Schulung ergibt sich dann als die Differenz zwischen diesen beiden potenziellen Ergebnissen:\n", "\n", "$${\\color{orange}{\\Delta}}_i = {\\color{blue}{Y}}_{i}^{{\\color{DarkGreen}{X=1}}} - {\\color{blue}{Y}}_{i}^{{\\color{DarkGreen}{X=0}}}$$\n", "\n", @@ -147,14 +147,14 @@ "\n", "- $i$ für die einzelne Beobachtung, hier die einzelne Person, steht;\n", "\n", - "- ${\\color{blue}{Y}}_i$ für das ${\\color{blue}\\text{Gehalt}}$ von $i$;\n", + "- ${\\color{blue}{Y}}_i$ für das $\\color{blue}{\\text{Gehalt}}$ von $i$;\n", "\n", - "- $\\color{DarkGreen}{X}$ für die Teilnahme an der ${\\color{DarkGreen}\\text{Schulung}}$; dabei ist $\\color{DarkGreen}{X_i=1}$ wenn $i$ teilnimmt und $\\color{DarkGreen}{X_i=0}$ wenn $i$ nicht teilnimmt." + "- $\\color{DarkGreen}{X}$ für die Teilnahme an der $\\color{DarkGreen}{\\text{Schulung}}$; dabei ist $\\color{DarkGreen}{X_i=1}$ wenn $i$ teilnimmt und $\\color{DarkGreen}{X_i=0}$ wenn $i$ nicht teilnimmt." ] }, { "cell_type": "markdown", - "id": "98fa67dd", + "id": "da357615", "metadata": {}, "source": [ "## Ein fiktives Beispiel\n", @@ -171,7 +171,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "87b960c5", + "id": "364f7658", "metadata": { "lines_to_next_cell": 2, "name": "gehaltstabelle", @@ -211,7 +211,7 @@ }, { "cell_type": "markdown", - "id": "83f7954d", + "id": "8d520da4", "metadata": {}, "source": [ "Der individuelle kausale Effekt ${\\color{orange}{\\Delta}}_i$ lässt sich dann innerhalb der Datentabelle `Schulung` berechnen als `gehalt1 - gehalt0` (hier in `R`):\n", @@ -229,7 +229,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "657baaf2", + "id": "9db8c758", "metadata": {}, "outputs": [], "source": [ @@ -242,7 +242,7 @@ }, { "cell_type": "markdown", - "id": "da2e5d29", + "id": "862783ff", "metadata": {}, "source": [ "Und damit:" @@ -251,7 +251,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "4a752d2a", + "id": "deab6549", "metadata": { "name": "gehaltstabelleeffekt", "tags": [ @@ -291,7 +291,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "be7415e2", + "id": "c81e0e61", "metadata": { "lines_to_next_cell": 2, "name": "visualisierung", @@ -334,7 +334,7 @@ { "cell_type": "code", "execution_count": null, - "id": "864b8063", + "id": "86739d3f", "metadata": { "name": "ike", "tags": [ @@ -354,7 +354,7 @@ }, { "cell_type": "markdown", - "id": "1227f3f4", + "id": "0bafad95", "metadata": {}, "source": [ "Sie sehen: häufig sind die individuellen kausalen Effekte positiv – sie können aber auch neutral oder sogar negativ sein.\n", @@ -363,7 +363,7 @@ "\n", "Das fundamentale Problem der kausalen Inferenz ist, dass wir den individuellen kausalen Effekt ${\\color{orange}{\\Delta}}_i = {\\color{blue}{Y}}_{i}^{{\\color{DarkGreen}{X=1}}} - {\\color{blue}{Y}}_{i}^{{\\color{DarkGreen}{X=0}}}$ **nicht** beobachten können.\n", "Es liegt je Beobachtung $i$ immer nur eines der beiden Potential Outcomes vor:\n", - "Entweder $\\color{blue}{Y}^{\\color{DarkGreen}{X=1}}$ ($\\color{blue}\\text{Gehalt}$ mit $\\color{DarkGreen}\\text{Schulung}$) **oder** $\\color{blue}{Y}^{\\color{DarkGreen}{X=0}}$ ($\\color{blue}\\text{Gehalt}$ ohne $\\color{DarkGreen}\\text{Schulung}$).\n", + "Entweder $\\color{blue}{Y}^{\\color{DarkGreen}{X=1}}$ ($\\color{blue}{\\text{Gehalt}}$ mit $\\color{DarkGreen}{\\text{Schulung}}$) **oder** $\\color{blue}{Y}^{\\color{DarkGreen}{X=0}}$ ($\\color{blue}{\\text{Gehalt}}$ ohne $\\color{DarkGreen}{\\text{Schulung}}$).\n", "\n", "- Wenn Person $i$ an der Schulung teilnimmt, liegt uns das Gehalt mit Schulung vor, ${\\color{blue}{Y}}_{i}^{{\\color{DarkGreen}{X=1}}}$, und nicht ${\\color{blue}{Y}}_{i}^{{\\color{DarkGreen}{X=0}}}$\n", "\n", @@ -378,7 +378,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e8506bd9", + "id": "59e24c61", "metadata": { "name": "cf", "tags": [ @@ -399,7 +399,7 @@ { "cell_type": "code", "execution_count": null, - "id": "190c0f1a", + "id": "bc054aa4", "metadata": { "lines_to_next_cell": 2, "name": "cfi", @@ -420,7 +420,7 @@ }, { "cell_type": "markdown", - "id": "301dffc3", + "id": "09e2f3e5", "metadata": {}, "source": [ "## Durchschnittlicher kausaler Effekt\n", @@ -437,40 +437,21 @@ }, { "cell_type": "code", - "execution_count": 7, - "id": "789e2f17", + "execution_count": null, + "id": "5716a6b3", "metadata": { "exercise": true, "lines_to_next_cell": 2, "name": "ate" }, - "outputs": [ - { - "data": { - "text/html": [ - "120" - ], - "text/latex": [ - "120" - ], - "text/markdown": [ - "120" - ], - "text/plain": [ - "[1] 120" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "mean( ~ effekt, data = Schulung)" ] }, { "cell_type": "markdown", - "id": "695a23c5", + "id": "fc891758", "metadata": {}, "source": [ "***\n", @@ -482,7 +463,7 @@ }, { "cell_type": "markdown", - "id": "5b5a0100", + "id": "7f3530eb", "metadata": {}, "source": [ "Analysiere die Variable `y` in Abhängigkeit der Variable `x` aus der Datentabelle `Daten`. Welche Funktion `analyse()` zur Anwendung kommt, hängt vom Ziel unser Analyse ab. \n", @@ -494,7 +475,7 @@ }, { "cell_type": "markdown", - "id": "0fe135e7", + "id": "0a418fab", "metadata": {}, "source": [ "***\n", @@ -510,7 +491,7 @@ }, { "cell_type": "markdown", - "id": "15710625", + "id": "801e1f9a", "metadata": {}, "source": [ "## Fehlende Werte\n", @@ -523,8 +504,8 @@ }, { "cell_type": "code", - "execution_count": 9, - "id": "02185248", + "execution_count": 7, + "id": "787d8b10", "metadata": { "name": "teilnahme", "tags": [ @@ -565,7 +546,7 @@ }, { "cell_type": "markdown", - "id": "afc8b5fd", + "id": "e7af1070", "metadata": {}, "source": [ "In der Regel strukturiert man die Daten so, dass nur eine Gehaltsvariable -- das beobachtete `gehalt` -- sowie eine Variable zur `teilnahme` existiert." @@ -573,8 +554,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "907d761c", + "execution_count": 8, + "id": "b1a9ed6a", "metadata": { "name": "gehalt", "tags": [ @@ -614,7 +595,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2ae1f46f", + "id": "f47c7f98", "metadata": { "name": "bias", "tags": [ @@ -634,7 +615,7 @@ }, { "cell_type": "markdown", - "id": "df873538", + "id": "9f708bd0", "metadata": {}, "source": [ "## Schätzung des kausalen Effektes\n", @@ -645,8 +626,8 @@ }, { "cell_type": "code", - "execution_count": 18, - "id": "c53a460a", + "execution_count": 10, + "id": "2e813853", "metadata": { "name": "gehaltteilnahme" }, @@ -688,7 +669,7 @@ }, { "cell_type": "markdown", - "id": "d5113505", + "id": "7b8e07f0", "metadata": {}, "source": [ "<!-- NOTE: Is it possible to use inline code eval here? -->\n", @@ -702,7 +683,7 @@ }, { "cell_type": "markdown", - "id": "4e977a16", + "id": "387bc565", "metadata": {}, "source": [ "*Anmerkung*: `round( mean(gehalt ~ teilnahme, data = Schulung), 2)` bedeutet aus `R mosaic` *übersetzt*:\n", @@ -721,7 +702,7 @@ }, { "cell_type": "markdown", - "id": "71362f14", + "id": "3de89924", "metadata": {}, "source": [ "Der naive Vergleich der Mittelwerte überschätzt hier den wahren durchschnittlichen Effekt.\n", @@ -739,13 +720,44 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "c3a88e91", + "execution_count": 9, + "id": "0b91df53", "metadata": { "exercise": true, "name": "po" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "<style>\n", + ".dl-inline {width: auto; margin:0; padding: 0}\n", + ".dl-inline>dt, .dl-inline>dd {float: none; width: auto; display: inline-block}\n", + ".dl-inline>dt::after {content: \":\\0020\"; padding-right: .5ex}\n", + ".dl-inline>dt:not(:first-of-type) {padding-left: .5ex}\n", + "</style><dl class=dl-inline><dt>Ja</dt><dd>2233.33333333333</dd><dt>Nein</dt><dd>2075</dd></dl>\n" + ], + "text/latex": [ + "\\begin{description*}\n", + "\\item[Ja] 2233.33333333333\n", + "\\item[Nein] 2075\n", + "\\end{description*}\n" + ], + "text/markdown": [ + "Ja\n", + ": 2233.33333333333Nein\n", + ": 2075\n", + "\n" + ], + "text/plain": [ + " Ja Nein \n", + "2233.333 2075.000 " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "mean(gehalt ~ teilnahme, data = Schulung)" ] @@ -753,7 +765,7 @@ { "cell_type": "code", "execution_count": null, - "id": "706bccb7", + "id": "98411f71", "metadata": { "name": "po-solution" }, @@ -770,7 +782,7 @@ { "cell_type": "code", "execution_count": null, - "id": "95df3eb8", + "id": "e7009e5e", "metadata": { "lines_to_next_cell": 2, "name": "po-hint" @@ -782,7 +794,7 @@ }, { "cell_type": "markdown", - "id": "5f5d9e76", + "id": "cceab59a", "metadata": {}, "source": [ "##\n", @@ -807,7 +819,7 @@ }, { "cell_type": "markdown", - "id": "d18bda47", + "id": "9fccf2b3", "metadata": {}, "source": [ "\n", @@ -817,7 +829,7 @@ ], "metadata": { "jupytext": { - "cell_metadata_filter": "tags,eval,exercise,name,-all", + "cell_metadata_filter": "tags,name,exercise,-all", "formats": "Rmd,ipynb", "notebook_metadata_filter": "-all" }, -- GitLab