\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "366ff202",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"
\n",
"
\n",
"
\n",
"- Now, you go back in time to 10:00 and you don't take an Aspirin.
\n",
"- Your pain goes away after 48 minutes.
\n",
"
\n",
"
\n",
"

\n",
"
\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "c3ca77ca",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"The **causal effect** of taking an Aspirin is 18 minutes (48 minutes - 30 minutes).\n"
]
},
{
"cell_type": "markdown",
"id": "a07027d9",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"id": "7859b66e",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Potential outcomes and randomized control trials\n",
"\n",
"- Establishing causality involves comparing these **potential outcomes**. "
]
},
{
"cell_type": "markdown",
"id": "b7a9922e",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- The problem is that we can never observe both taking an Aspirin and not taking as Aspirin (in the same person at the same time under the same conditions)."
]
},
{
"cell_type": "markdown",
"id": "9e350596",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- A close approximation to comparing potential outcomes is to compare two groups of people that are similar on average (age, sex, income, etc.) except one group is allowed to take Aspirin after a headache and the other group takes a fake Aspirin (sugar pill/placebo) after a headache. This is an example of a randomized control trial."
]
},
{
"cell_type": "markdown",
"id": "8d4f8cd5-2b31-46d3-aad4-897bbb3021e2",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- Then the mean difference between time to pain relief should be due to Aspirin and not other factors related to why people may or may not take an Aspirin. "
]
},
{
"cell_type": "markdown",
"id": "5c44bf71-07a9-46af-aa37-6f46db59c025",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Does Material Deprivation Cause increases in mental health visits?\n",
"\n",
"- Neighbourhoods can't be randomly assigned to high or low deprivationdepravity, like people could be randomized to take a real or fake Aspirin.\n",
"\n",
"- There could be many other factors related to why a neighbourhood has a low or high deprivation score. \n",
"\n",
"- This means that when we are comparing neighbourhoods with low deprivation to high deprivation the differences in a certain outcome such as mental health visit rates could be due to factors other than deprivation such as environmental factors that are associated with mental illness, but happen to be more or less prevalent in one of the deprivation groups.\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "a13007b5-a193-4a36-b630-906be48578dc",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Just in case you have seen a two-sample t-test ...\n",
"\n",
"This is similar to a two-sample t-test (we won't cover in this course except here) except not as flexible. "
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "9be7e8d7-eb51-45a5-b774-e2c7eb8348d1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The p-value from the two-sample t-test is: 0.0\n"
]
}
],
"source": [
"from scipy import stats\n",
"\n",
"mh_visits_low = mh_visit_depriv.loc[\n",
" mh_visit_depriv[\"depriv_binary\"] == \"Low\", \"mh_visit_rates_mf\"]\n",
"\n",
"mh_visits_high = mh_visit_depriv.loc[\n",
" mh_visit_depriv[\"depriv_binary\"] == \"High\", \"mh_visit_rates_mf\"]\n",
"\n",
"statistic, pvalue = stats.ttest_ind(mh_visits_high, mh_visits_low)\n",
"\n",
"print(\"The p-value from the two-sample t-test is: \", round(pvalue, 3))"
]
},
{
"cell_type": "markdown",
"id": "798bf90b",
"metadata": {},
"source": [
"The two-sample t-test involves: \n",
"\n",
"1. Computing $t_{\\text observed} = \\frac{\\bar{x_{\\text Low}} - \\bar{x_{\\text High}}}{SD}$, where $SD$ is an estimate of the standard deviation of the mean difference.\n",
"\n",
"2. Computing the p-value using $t_{\\text observed}$ and the appropriate $t$-distribution.\n",
"\n",
"3. Assessing several statistical assumptions about the data to ensure the accuracy of the p-value.\n"
]
},
{
"cell_type": "markdown",
"id": "5a671c9e",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Review of this class\n",
"\n",
"- Comparing two samples by simulating the distribution of a test statistic (e.g., the difference in two means) assuming the null hypothesis is true (i.e., there is no difference in the means) performs a statistical test:\n",
"\n",
" \n",
" 1. Stated the null and alternative hypotheses;\n",
" \n",
" 2. imulated the test statistic assuming the null hypotheis by:\n",
" \n",
" + Randomly shuffling the group labels (e.g., high/low deprivation);\n",
" \n",
" + Calculating the test statistic in the shuffled data se; and\n",
" \n",
" + Repeating the previous two steps a large number of times (e.g., 5,000).\n",
" \n",
" 3. Computed the p-value as a measure of how consistent the data are with the null hypothesis. \n",
"\n",
" + The p-value is computed by summing the number of simulated values that are more extreme in the positive or negative direction.\n"
]
},
{
"cell_type": "markdown",
"id": "9575cf62",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"\n",
"- If the p-value is small then the data are inconsistent with the null hypothesis and there is evidence in support of the alternative hypothesis.\n",
"\n",
"- A large p-value isn't an indication of evidence in support of the null hypothesis. The procedure only tests whether you have data inconsistent with the null hypothesis.\n",
"\n",
"- A small p-value may not be **causal** evidence that for the alternative hypothesis unless random assignment was used part of the study design."
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "ggr274",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}