{ "cells": [ { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "# Ch11 Why Model?" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "Data cannot speak for themselves, 所以我们需要简单非参数模型到各种参数模型。本文的内容如下:\n", "\n", "- 教材对应章节的内容摘要\n", "- 教材中的 Programs" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false", "toc-hr-collapsed": true }, "source": [ "## 内容摘要" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "本章描述了本书 Part I 中使用的非参数估计量与 Part II 中使用的基于模型的参数估计量之间的区别。它还回顾了 smoothing 的概念,并简要回顾了任何建模决策中涉及的 bias-variance trade-off。本章motivates the need for models in data analysis,无论分析目标是因果推理还是预测。We will take a break from causal considerations until the next chapter. 请记住,有关建模的统计文献非常丰富;本章只能重点介绍一些关键问题。" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "**Big Picturce:**\n", "\n", "非参数模型 --> parametric models --> structural mean models\n", "\n", "- Models for the marginal mean of a counterfactual outcome are referred to as **marginal structural mean models**.\n", "- Effect modification and marginal structural models 在上面的模型增加新的变量 for effect modification\n", "- Structural nested mean model 会有一个对比某个基准 potential outcome.\n", "\n", "In Part II of this book we have described two different types of models for causal inference: \n", "\n", "- propensity models and \n", "- structural models. \n", "\n", "Let us now compare them. \n", "\n", "- Propensity models are models for the probability of treatment $A$ given the variables $L$ used to try to achieve conditional exchangeability. \n", "- Structural models describe the relation between the treatment $A$ and some component of the distribution (e.g., the mean) of the counterfactual outcome" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "Table of contents\n", "\n", "- Data cannot speak for themselves\n", "- Parametric estimators of the conditional mean\n", "- Nonparametric estimators of the conditional mean\n", "- Smoothing\n", "- The bias-variance trade-off" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### 11.1 Data cannot speak for themselves\n", "\n", "考虑一个研究总体,其中有16个人感染了人类免疫缺陷病毒(HIV)。与本书第一部分不同,我们不会将这些人视为 representatives of 1 billion individuals identical to them. Rather, these are just 16 individuals randomly sampled from a large, possibly hypothetical super-population: the target population.\n", "\n", "在研究开始时,每个人都会接受一定程度的治疗 $A$ (antiretroviral therapy), which is maintained during the study. At the end of the study, a continuous outcome $Y$ (CD4 cell count, in cells/mm3) is measured in all individuals. 我们希望一致的估算\n", " the mean of $Y$ among individuals with treatment level $A = a$ in the population from which the 16 individuals were randomly sampled. 也就是说,估计是未知的总体参数 $E[Y^{a=1} - Y^{a=0}|A=a]$.\n" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### 11.2 Parametric estimators of the conditional mean\n", "\n", "\n", "当使用参数模型时,只有在模型中编码的限制正确(i.e. if the model is correctly specified)的情况下,推断才是正确的。因此,基于模型的因果推断(本书其余大部分内容都基于此因果推断)依赖于(approximately)没有模型错误指定的条件。由于很少(甚至从来没有)完美地指定参数模型,因此几乎总是会期望一定程度的模型指定错误。This can be at least partially rectified by using nonparametric estimators,我们将在下一部分中进行描述。" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### 11.3 Nonparametric estimators of the conditional mean" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "- In this book we define “model” as an a priori mathematical restriction on the possible states of nature (Robins, Greenland 1986). Part I was entitled “Causal inference without models” because it only described **saturated models**.\n", "- 本书 Part II 中描述的大多数因果推断方法都依赖于 estimators that are parametric estimators of some part of the distribution of the data. Parametric estimation and other approaches to borrow information 是我们唯一的希望,因为多数情况下数据不能自己说话。" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### 11.4 Smoothing" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### 11.5 The bias-variance trade-off" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "这种偏差-方差分析是数据分析的核心。Investigators using models need to decide whether some protection against bias–by, say, adding more parameters to the model–is worth the cost in terms of variance. 尽管存在一些有助于这些决定的正式程序,但实际上,许多研究人员会根据诸如传统,参数的可解释性和软件可用性等标准来决定使用哪种模型。在本书中,我们通常会假设正确指定了我们的参数模型。这是一个不现实的假设,但它使我们能够专注于因果分析所特有的问题。毕竟,Model misspecification 是在任何类型的数据分析中都可能出现的问题,无论估计值是否具有因果关系。在实践中,谨慎的研究人员将始终对模型的有效性提出质疑,并将 conduct an analysis to assess the sensitivity of their estimates to model specification." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "## Setup and imports\n", "import warnings\n", "import numpy as np\n", "import pandas as pd\n", "import statsmodels.api as sm\n", "import scipy.stats\n", "import matplotlib.pyplot as plt\n", "\n", "warnings.filterwarnings('ignore')\n", "%matplotlib inline\n" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false", "toc-hr-collapsed": true }, "source": [ "## Programs" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### Program 11.1\n", "\n", "Half of the individuals were treated $(A = 1)$. Figure 11.1 is a scatter plot that displays each of the 16 individuals as a dot. The height of the dot indicates the value of the individual’s outcome $Y$." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "df1 = pd.DataFrame({\n", " 'A': [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],\n", " 'Y': [\n", " 200, 150, 220, 110, 50, 180, 90, 170,\n", " 170, 30, 70, 110, 80, 50, 10, 20\n", " ]\n", "})" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfgAAAF3CAYAAABJzllyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9t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ttJvjfJDw47EnAhr+ABoENewQNAhwQeADok8ADQIYEHgA4JPAB0SOABoEMCDwAdEngA6JDAA0CH/j+E0TOwhO+vKgAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "fig, ax = plt.subplots(figsize=(8, 6))\n", "\n", "ax.scatter(df1['A'], df1['Y'])\n", "ax.set_xlabel('A', fontsize=14)\n", "ax.set_ylabel('Y', fontsize=14);" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "Our estimate of the population mean in the treated is the sample aver- age 146.25 for those with $A = 1$, and our estimate of the population mean in the untreated is the sample average 67.50 in those with $A = 0$." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Y
countmeanstdmin25%50%75%max
A
08.067.5053.11712110.027.560.087.5170.0
18.0146.2558.29420550.0105.0160.0185.0220.0
\n", "
" ], "text/plain": [ " Y \n", " count mean std min 25% 50% 75% max\n", "A \n", "0 8.0 67.50 53.117121 10.0 27.5 60.0 87.5 170.0\n", "1 8.0 146.25 58.294205 50.0 105.0 160.0 185.0 220.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1.groupby('A').describe()" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "\"Now suppose treatment $A$ is a polytomous variable that can take 4 possible values\". Now suppose treatment $A$ is a polytomous variable that can take 4 possible values: no treatment $(A = 1)$, low-dose treatment $(A = 2)$, medium-dose treatment $(A = 3)$, and high-dose treatment $(A = 4)$." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "df2 = pd.DataFrame({\n", " 'A': [\n", " 1, 1, 1, 1, 2, 2, 2, 2,\n", " 3, 3, 3, 3, 4, 4, 4, 4\n", " ],\n", " 'Y': [\n", " 110, 80, 50, 40, 170, 30, 70, 50,\n", " 110, 50, 180, 130, 200, 150, 220, 210\n", " ]\n", "})" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfgAAAF3CAYAAABJzllyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAbKElEQVR4nO3df3Bld3nf8fdTWaVqIRXEArxrbxaI0QAu3QWN444H6gKtMKX20kJiT2oMMSzOwBQmVMVyZkJK+weN+JFQJmSW4rFNjWOChXCpqXAMwaVTQ7SWY5ksCjY1eLU79mIj24xv3V356R862tXK0lralc6596v3a+aO7n3OubqPj7+rj865X91vZCaSJKksf6vpBiRJ0voz4CVJKpABL0lSgQx4SZIKZMBLklQgA16SpAKd1nQD6+n000/P7du3N92GJEm12bt3788ys29pvaiA3759OxMTE023IUlSbSLiJ8vVvUQvSVKBagv4iDgrIr4dEfsi4gcR8cGqPhIRP4yIeyLiqxHRW9W3R0QrIu6ubn9SV6+SJHW6Os/gjwAfzsxXAOcB74+IVwK3Aedk5quBvwGGFz3n/szcUd2urLFXSZI6Wm0Bn5kHM/Ou6v4TwD5ga2Z+MzOPVLvdCZxZV0+SJJWqkffgI2I7sBP43pJNvwV8Y9Hjl0TEZER8JyJeV1N7kiR1vNpn0UfEc4GbgQ9l5uOL6r/L/GX8G6rSQWBbZj4SEa8FxiLiVYufUz1vN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LM/PpJvqT5Hvwkk7OFcC3l4Z75c+AXwHeVG9LkhbzDF6SpAJ5Bi9JUoEMeEmSCmTAS5JUIANekqQCGfCSJBXIgJckqUAGvCRJBTLgJUkqkAEvSVKB/j9OnT5eH2MZ+AAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "fig, ax = plt.subplots(figsize=(8, 6))\n", "\n", "ax.scatter(df2['A'], df2['Y'])\n", "ax.set_xlabel('A', fontsize=14)\n", "ax.set_ylabel('Y', fontsize=14);" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "Collapsed": "false", "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Y
countmeanstdmin25%50%75%max
A
14.070.031.62277740.047.565.087.5110.0
24.080.062.18252730.045.060.095.0170.0
34.0117.553.77421950.095.0120.0142.5180.0
44.0195.031.091264150.0187.5205.0212.5220.0
\n", "
" ], "text/plain": [ " Y \n", " count mean std min 25% 50% 75% max\n", "A \n", "1 4.0 70.0 31.622777 40.0 47.5 65.0 87.5 110.0\n", "2 4.0 80.0 62.182527 30.0 45.0 60.0 95.0 170.0\n", "3 4.0 117.5 53.774219 50.0 95.0 120.0 142.5 180.0\n", "4 4.0 195.0 31.091264 150.0 187.5 205.0 212.5 220.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2.groupby('A').describe()" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### Program 11.2\n", "\n", "Finally, suppose that treatment $A$ is a variable representing the dose of treatment in mg/day, and that it takes integer values from 0 to 100 mg. This creates a problem: how can we estimate the mean of the outcome $Y$ among individuals with treatment level $A = 90$ in the target population?\n", "\n", "上面的描述表明,我们不能总是让数据“为自己说话”以获得有意义的估计。相反,我们经常需要用模型来补充数据,如我们在下一节中所述。" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "A, Y = zip(*(\n", " (3, 21),\n", " (11, 54),\n", " (17, 33),\n", " (23, 101),\n", " (29, 85),\n", " (37, 65),\n", " (41, 157),\n", " (53, 120),\n", " (67, 111),\n", " (79, 200),\n", " (83, 140),\n", " (97, 220),\n", " (60, 230),\n", " (71, 217),\n", " (15, 11),\n", " (45, 190),\n", "))" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "df3 = pd.DataFrame({'A': A, 'Y': Y, 'constant': np.ones(16)})" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfoAAAF3CAYAAABNO4lPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAWdElEQVR4nO3df4xlZ3kf8O/T9aadkFaDa0O9YyeG1ppC44ZFK+qWKHJD1ME0irdWUInaxEJQVxVRSZtM8eYf+lOm3TRpUAKSGygmIlBKlsVKo2yRoSWtBGGdiVgTZ4RFwPasa29CBmiZJsvy9o+5Y8/as7uenb33zLz385FG9573nrnz6OhovnPe8859qrUWAKBPf2roAgCA8RH0ANAxQQ8AHRP0ANAxQQ8AHRP0ANCxq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rIf8B1prx0bDT25MHY0enxqqvj3q1Ul+qKq+lPVbS9+f9Sv82dG0aOK8vVyPJ3m8tfaZ0fZHsh78ztmd+YEkv99aO9NaO5vkWJK/EefslXShc3TbmTYNQf/ZJDeNVoN+W9YXjNw/cE170ui+8XuSPNxa+9lNL92f5M7R8zuTfGzSte1lrbUjrbXrW2s3Zv38/ERr7e8l+WSSHx7t5rhehtba/07yWFXNj4Zek+R345zdqUeT3FJV3z76vbBxXJ2zV86FztH7k/zYaPX9LUm+ujHFfyFT8YE5VfW6rF8h7Uvy3tbavxm4pD2pqr43yW8mOZVn7iX/dNbv0384yXdm/RfA61trz15YwvNQVbcm+anW2g9W1UuzfoV/dZKlJH+/tfbHQ9a3F1XVK7K+yPHbknwxyRuzfpHjnN2BqvoXSf5u1v8bZynJm7N+r9g5u01V9cEkt2a9S92TSd6e5Hi2OEdHf1j9QtZX6X8jyRtbaycv+v7TEPQAMK2mYeoeAKaWoAeAjgl6AOiYoAeAjgl6AOiYoAeAjgl6YEeq6mBVnauq/zV0LcBzCXpgp/5Bkncl+e6qetnQxQDn84E5wGWrqpmsdy/7viRvTfJHrbWfGrYqYDNX9MBO/HCSL7fWPpfkl7P+Gdz7B64J2ETQAzvx5qwHfJL8j6x/9vYPDVcO8GyCHrgsVfWXst5i91eSpK3fB/xA1sMf2CWuuvQuAFt6c9Y7Qj663lArSVJJUlU3tNYeG6ow4BkW4wHbVlVXJXksyc8n+bVnvfzLST7aWvuXEy8MeA5BD2xbVd2e5CNJ/kJr7Q+f9drbkvyjJC9trX1riPqAZ7hHD1yONyX55LNDfuS/JPmuJD8w2ZKArbiiB4COuaIHgI4JegDomKAHgI4JegDomKAHgI4JegDomKAHgI4JegDomKAHgI79f91ts94yDWGCAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "fig, ax = plt.subplots(figsize=(8, 6))\n", "\n", "ax.scatter(df3.A, df3.Y)\n", "ax.set_xlabel('A', fontsize=14)\n", "ax.set_ylabel('Y', fontsize=14);" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "\"The values $\\hat{\\theta}_0$ and $\\hat{\\theta}_1$ can be easily computed using linear algebra, as described in any statistics textbook.\"\n", "\n", "Briefly, make $X$ be the matrix with ones in the first column and $A$ in the second column, and make $Y$ an $n \\times 1$ matrix. Then $\\hat{\\theta}_0$ and $\\hat{\\theta}_1$ are calculated as $\\hat\\theta = (X^TX)^{-1}X^TY$" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "array([[24.54636872],\n", " [ 2.13715198]])" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X = np.ones((df3.shape[0], 2)) # make X a matrix of ones\n", "X[:, 1] = df3.A # replace second column with A\n", "Y = np.array(df3.Y).reshape((-1, 1)) # make Y an n x 1 matrix\n", "\n", "theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Y)\n", "theta" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "theta0 est.: 24.55\n", "theta1 est.: 2.14\n" ] } ], "source": [ "print(\"theta0 est.: {:>5.2f}\".format(theta[0][0]))\n", "print(\"theta1 est.: {:>5.2f}\".format(theta[1][0]))" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "E[Y|A=90] est.: 216.9\n" ] } ], "source": [ "expectation_at_90 = theta[0][0] + 90 * theta[1][0]\n", "print(\"E[Y|A=90] est.: {:>5.1f}\".format(expectation_at_90))" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "We can also compute this with a statistics package, like Statsmodels, which will also give us confidence intervals and other values" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "ols = sm.OLS(Y, df3[['constant', 'A']])\n", "res = ols.fit()" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err t P>|t| [0.025 0.975]
constant 24.5464 21.330 1.151 0.269 -21.202 70.295
A 2.1372 0.400 5.347 0.000 1.280 2.994
" ], "text/plain": [ "" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "summary = res.summary()\n", "summary.tables[1]" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "Initially, it wasn't clear how to get confidence intervals for expected values from Statsmodels, so the next cells calculate them from scratch." ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "n = df3.shape[0]\n", "yvar = (res.resid * res.resid).sum() / (n - 2) # = res.mse_resid\n", "xval = np.array([[1, 90]])\n", "X = df3[['constant', 'A']]\n", "XpXinv = np.linalg.inv(np.dot(X.T, X))\n", "se_mean = np.sqrt(yvar * np.dot(xval, np.dot(XpXinv, xval.T)))[0, 0]" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " estimate 95% C.I.\n", "E[Y|A=90] 216.89 (172.15, 261.63)\n" ] } ], "source": [ "t = scipy.stats.t.ppf(0.975, n - 2)\n", "ypred = res.predict([[1, 90]])[0]\n", "print(' estimate 95% C.I.')\n", "print(\n", " 'E[Y|A=90] {:>6.2f} ({:>6.2f}, {:>6.2f})'.format(\n", " ypred, ypred - t * se_mean, ypred + t * se_mean\n", "))" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "Here's an easier way to calculate the confidence intervals, contributed by GitHub user @pettypychen" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
meanmean_semean_ci_lowermean_ci_upperobs_ci_lowerobs_ci_upper
0216.8920.86172.15261.63112.27321.51
\n", "
" ], "text/plain": [ " mean mean_se mean_ci_lower mean_ci_upper obs_ci_lower obs_ci_upper\n", "0 216.89 20.86 172.15 261.63 112.27 321.51" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred = res.get_prediction(exog=[1, 90])\n", "pred.summary_frame().round(2)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "Collapsed": "false", "scrolled": true }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfoAAAF3CAYAAABNO4lPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXhU5fnG8fslBI0IRASBBDAgGARkM2wiiICERQv+qtZWxZ1apdbWphJFQdwocbetldYNd6sxUqRERAF3DUQIWxAFgSTshjVASN7fH5mcJBgg28yZOfP9XBdX8rwzCY/jITfPnMN5jbVWAADAm+q53QAAAPAfgh4AAA8j6AEA8DCCHgAADyPoAQDwMIIeAAAPq+92A3WpWbNmNi4uzu02AAAImMWLF2+31jY/2uOeCvq4uDhlZGS43QYAAAFjjPnxWI/z1j0AAB5G0AMA4GEEPQAAHkbQAwDgYQQ9AAAeRtADAOBhBD0AAB5G0AMA4GEEPQAAHkbQAwDgYQQ9AAAeRtADABAA+fsPacOO/QH/fT21qQ0AHEtaZo5S0rOVm1+gmOgoJSXGa2zPWLfbQhiYPne1/rHge0nSuodHyRgTsN+boAcQFtIyc5ScmqWCwiJJUk5+gZJTsySJsIffbNl9QH0fmu/Uk0afFdCQlwh6AGEiJT3bCflS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Vr7Z3e7AlAeEz2A2rhU0o/W2mWSXlbJPbgjXe4JQDkEPYDauFElAS9JC1Vy7+1fuNcOgCMR9ABqxBjTQSVb7L4mSbbkPOCrKgl/AEGi/vGfAgCVulElO0JuKNlQS5JkJMkY08Zau9GtxgCU4WI8ANVmjKkvaaOkJyXNPuLhlyW9a62dGvDGAPwMQQ+g2owxYyS9LamltXbHEY/dKel3ktpba4vd6A9AGc7RA6iJGyR9fGTI+/xH0umShgW2JQCVYaIHAMDDmOgBAPAwgh4AAA8j6AEA8DCCHgAADyPoAQDwMIIeAAAPI+gBAPAwgh4AAA8j6AEA8LD/B5P0WwAUAtg3AAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "fig, ax = plt.subplots(figsize=(8, 6))\n", "\n", "ax.scatter(df3.A, df3.Y)\n", "ax.plot(df3.A, res.predict(df3[['constant', 'A']]))\n", "ax.set_xlabel('A', fontsize=14)\n", "ax.set_ylabel('Y', fontsize=14);" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "(Still Program 11.2)" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "\"Let us return to the data in Figure 11.1.\"" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "df1['constant'] = 1" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "ols = sm.OLS(df1['Y'], df1[['constant', 'A']])\n", "res = ols.fit()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err t P>|t| [0.025 0.975]
constant 67.5000 19.716 3.424 0.004 25.213 109.787
A 78.7500 27.883 2.824 0.014 18.947 138.553
" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res.summary().tables[1]" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "E[Y|A=0] est.: 67.50\n", "E[Y|A=1] est.: 146.25\n" ] } ], "source": [ "est_at_0 = res.params[0]\n", "est_at_1 = res.params[0] + res.params[1]\n", "print(\"E[Y|A=0] est.: {:>6.2f}\".format(est_at_0))\n", "print(\"E[Y|A=1] est.: {:>6.2f}\".format(est_at_1))" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### Program 11.3" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "Starting from the same data as Section 11.2, Program 11.2" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "df3['A^2'] = df3.A * df3.A" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "ols = sm.OLS(df3.Y, df3[['constant', 'A', 'A^2']])\n", "res = ols.fit()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err t P>|t| [0.025 0.975]
constant -7.4069 31.748 -0.233 0.819 -75.994 61.180
A 4.1072 1.531 2.683 0.019 0.800 7.414
A^2 -0.0204 0.015 -1.331 0.206 -0.053 0.013
" ], "text/plain": [ "" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "summary = res.summary()\n", "summary.tables[1]" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfoAAAF3CAYAAABNO4lPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2Z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+VKGm2MifX/XKg9r1yzTedI1+g7kq73z74fLamsdoj/SCJiwRxjzI/k6yFFSXreWvsnh0sKS8aYMyUtkZSt7+8lPyDfffo3JPWU7wfAFdbawyeW4DgYY86V9Atr7SXGmD7y9fDjJWVJus5aW+FkfeHIGDNUvkmOLSRtlnSjfJ0crtlGMMb8r6Qr5XsaJ0vSLfLdK+aabSBjzOuSzpVvl7rtkn4raaHquUb9v1g9Kd8s/XJJN1prM4/6/pEQ9AAARKpIGLoHACBiEfQAALgYQQ8AgIsR9AAAuBhBDwCAixH0AAC4GEEPoFGMManGGK8x5gunawHwQwQ9gMa6VdJTkgYaY051uhgAh2LBHAAnzBgTI9/uZWdLukfSbmvtL5ytCkBd9OgBNMZESVuttaskvSzfGtzRDtcEoA6CHkBj3CJfwEvSZ/Ktvf0T58oBcDiCHsAJMcb0k2+L3dckyfruA74qX/gDCBHNj30IANTrFvl2hMz1baglSTKSZIzpYa3Nc6owAN9jMh6ABjPGNJeUJ+nvkt497MsvS1pgrf190AsD8AMEPYAGM8aMk/SWpK7W2l2Hfe1Xku6Q1MdaW+NEfQC+xz16ACfiZkmfHB7yfm9K6iXpwuCWBKA+9OgBAHAxevQAALgYQQ8AgIsR9AAAuBhBDwCAixH0AAC4GEEPAICLEfQAALgYQQ8AgIsR9AAAuNj/B0azvqcWmvf0AAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "df3.sort_values('A', inplace=True)\n", "\n", "fig, ax = plt.subplots(figsize=(8, 6))\n", "\n", "ax.scatter(df3.A, df3.Y)\n", "ax.plot(df3.A, res.predict(df3[['constant', 'A', 'A^2']]))\n", "ax.set_xlabel('A', fontsize=14)\n", "ax.set_ylabel('Y', fontsize=14);" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "The expected value and confidence interval can be obtained with the method contributed by @pettypychen above" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
meanmean_semean_ci_lowermean_ci_upperobs_ci_lowerobs_ci_upper
0197.1325.16142.77251.4989.63304.62
\n", "
" ], "text/plain": [ " mean mean_se mean_ci_lower mean_ci_upper obs_ci_lower obs_ci_upper\n", "0 197.13 25.16 142.77 251.49 89.63 304.62" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred = res.get_prediction(exog=[1, 90, 90**2])\n", "pred.summary_frame().round(2)" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false", "toc-hr-collapsed": false }, "source": [ "## 解读知识点\n" ] }, { "cell_type": "markdown", "metadata": { "Collapsed": "false" }, "source": [ "### 估计置信区间" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "import numpy as np\n", "import pandas as pd\n", "import statsmodels.api as sm\n", "import scipy.stats\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err t P>|t| [0.025 0.975]
constant -7.4069 31.748 -0.233 0.819 -75.994 61.180
A 4.1072 1.531 2.683 0.019 0.800 7.414
A^2 -0.0204 0.015 -1.331 0.206 -0.053 0.013
" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A, Y = zip(*(\n", " (3, 21),\n", " (11, 54),\n", " (17, 33),\n", " (23, 101),\n", " (29, 85),\n", " (37, 65),\n", " (41, 157),\n", " (53, 120),\n", " (67, 111),\n", " (79, 200),\n", " (83, 140),\n", " (97, 220),\n", " (60, 230),\n", " (71, 217),\n", " (15, 11),\n", " (45, 190),\n", "))\n", "\n", "df3 = pd.DataFrame({'A': A, 'Y': Y, 'constant': np.ones(16)})\n", "\n", "df3['A^2'] = df3.A * df3.A\n", "\n", "ols = sm.OLS(df3.Y, df3[['constant', 'A', 'A^2']])\n", "res = ols.fit()\n", "\n", "summary = res.summary()\n", "summary.tables[1]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "Collapsed": "false", "scrolled": true }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfoAAAF3CAYAAABNO4lPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXxU1f3/8fchBEjYYtgTtgAxyh4Ii/tuoNWCiHVFXFGrP5daWrBf2367aaVVa60LiOIOLix+3VKlLlQrEAwSFsMqWYFASFgyZJmc3x8zwYBhCcnMnbnzej4ePJI5uUw+Xi9555x77jnGWisAAOBOzZwuAAAABA5BDwCAixH0AAC4GEEPAICLEfQAALgYQQ8AgIs1d7qAptSxY0fbu3dvp8sAACBoVqxYsdNa2+lIX3dV0Pfu3VuZmZlOlwEAQNAYY7Ye7esM3QMA4GIEPQAALkbQAwDgYgQ9AAAuRtADAOBiBD0AAC5G0AMA4GIEPQAALkbQAwDgYq5aGQ8AjmZhVoFmZOSosNSjhLgYTU1P0fjURKfLAgKKoAcQERZmFWj6/Gx5qrySpIJSj6bPz5Ykwh6uxtA9gIgwIyPnYMjX8lR5NSMjx6GKgOAg6AFEhMJST4PaAbcg6AFEhIS4mAa1A25B0AOICFPTUxQTHXVIW0x0lKampzhUERAcTMYDEBFqJ9wx6x6RhqAHEDHGpyYS7Ig4DN0DAOBiBD0AAC5G0AMA4GIEPQAALkbQAwDgYgQ9AAAu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R9AAAuBhBDwCAixH0AAC4GEEPAICLEfQAALgYQQ8AgIsR9AAAuNj/B0azvqcWmvf0AAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "df3.sort_values('A', inplace=True)\n", "fig, ax = plt.subplots(figsize=(8, 6))\n", "ax.scatter(df3.A, df3.Y)\n", "ax.plot(df3.A, res.predict(df3[['constant', 'A', 'A^2']]))\n", "ax.set_xlabel('A', fontsize=14)\n", "ax.set_ylabel('Y', fontsize=14);" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
meanmean_semean_ci_lowermean_ci_upperobs_ci_lowerobs_ci_upper
0197.1325.16142.77251.4989.63304.62
\n", "
" ], "text/plain": [ " mean mean_se mean_ci_lower mean_ci_upper obs_ci_lower obs_ci_upper\n", "0 197.13 25.16 142.77 251.49 89.63 304.62" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred = res.get_prediction(exog=[1, 90, 90**2])\n", "pred.summary_frame().round(2)" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "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.7.4" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": { "height": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "165px" }, "toc_section_display": true, "toc_window_display": true }, "toc-autonumbering": false }, "nbformat": 4, "nbformat_minor": 4 }