{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quasi-binomial regression\n", "\n", "This notebook demonstrates using custom variance functions and non-binary data\n", "with the quasi-binomial GLM family to perform a regression analysis using\n", "a dependent variable that is a proportion.\n", "\n", "The notebook uses the barley leaf blotch data that has been discussed in\n", "several textbooks. See below for one reference:\n", "\n", "https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_glimmix_sect016.htm" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:49.261749Z", "iopub.status.busy": "2021-02-02T06:54:49.260792Z", "iopub.status.idle": "2021-02-02T06:54:50.675737Z", "shell.execute_reply": "2021-02-02T06:54:50.676432Z" } }, "outputs": [], "source": [ "import statsmodels.api as sm\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from io import StringIO" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The raw data, expressed as percentages. We will divide by 100\n", "to obtain proportions." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:50.684663Z", "iopub.status.busy": "2021-02-02T06:54:50.683808Z", "iopub.status.idle": "2021-02-02T06:54:50.687970Z", "shell.execute_reply": "2021-02-02T06:54:50.689001Z" } }, "outputs": [], "source": [ "raw = StringIO(\"\"\"0.05,0.00,1.25,2.50,5.50,1.00,5.00,5.00,17.50\n", "0.00,0.05,1.25,0.50,1.00,5.00,0.10,10.00,25.00\n", "0.00,0.05,2.50,0.01,6.00,5.00,5.00,5.00,42.50\n", "0.10,0.30,16.60,3.00,1.10,5.00,5.00,5.00,50.00\n", "0.25,0.75,2.50,2.50,2.50,5.00,50.00,25.00,37.50\n", "0.05,0.30,2.50,0.01,8.00,5.00,10.00,75.00,95.00\n", "0.50,3.00,0.00,25.00,16.50,10.00,50.00,50.00,62.50\n", "1.30,7.50,20.00,55.00,29.50,5.00,25.00,75.00,95.00\n", "1.50,1.00,37.50,5.00,20.00,50.00,50.00,75.00,95.00\n", "1.50,12.70,26.25,40.00,43.50,75.00,75.00,75.00,95.00\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The regression model is a two-way additive model with\n", "site and variety effects. The data are a full unreplicated\n", "design with 10 rows (sites) and 9 columns (varieties)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:50.693554Z", "iopub.status.busy": "2021-02-02T06:54:50.692228Z", "iopub.status.idle": "2021-02-02T06:54:50.714471Z", "shell.execute_reply": "2021-02-02T06:54:50.715479Z" } }, "outputs": [], "source": [ "df = pd.read_csv(raw, header=None)\n", "df = df.melt()\n", "df[\"site\"] = 1 + np.floor(df.index / 10).astype(np.int)\n", "df[\"variety\"] = 1 + (df.index % 10)\n", "df = df.rename(columns={\"value\": \"blotch\"})\n", "df = df.drop(\"variable\", axis=1)\n", "df[\"blotch\"] /= 100" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fit the quasi-binomial regression with the standard variance\n", "function." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:50.720221Z", "iopub.status.busy": "2021-02-02T06:54:50.718789Z", "iopub.status.idle": "2021-02-02T06:54:50.776744Z", "shell.execute_reply": "2021-02-02T06:54:50.777725Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Generalized Linear Model Regression Results \n", "==============================================================================\n", "Dep. Variable: blotch No. Observations: 90\n", "Model: GLM Df Residuals: 72\n", "Model Family: Binomial Df Model: 17\n", "Link Function: logit Scale: 0.088778\n", "Method: IRLS Log-Likelihood: -20.791\n", "Date: Tue, 02 Feb 2021 Deviance: 6.1260\n", "Time: 06:54:50 Pearson chi2: 6.39\n", "No. Iterations: 10 \n", "Covariance Type: nonrobust \n", "==================================================================================\n", " coef std err z P>|z| [0.025 0.975]\n", "----------------------------------------------------------------------------------\n", "C(variety)[1] -8.0546 1.422 -5.664 0.000 -10.842 -5.268\n", "C(variety)[2] -7.9046 1.412 -5.599 0.000 -10.672 -5.138\n", "C(variety)[3] -7.3652 1.384 -5.321 0.000 -10.078 -4.652\n", "C(variety)[4] -7.0065 1.372 -5.109 0.000 -9.695 -4.318\n", "C(variety)[5] -6.4399 1.357 -4.746 0.000 -9.100 -3.780\n", "C(variety)[6] -5.6835 1.344 -4.230 0.000 -8.317 -3.050\n", "C(variety)[7] -5.4841 1.341 -4.090 0.000 -8.112 -2.856\n", "C(variety)[8] -4.7126 1.331 -3.539 0.000 -7.322 -2.103\n", "C(variety)[9] -4.5546 1.330 -3.425 0.001 -7.161 -1.948\n", "C(variety)[10] -3.8016 1.320 -2.881 0.004 -6.388 -1.215\n", "C(site)[T.2] 1.6391 1.443 1.136 0.256 -1.190 4.468\n", "C(site)[T.3] 3.3265 1.349 2.466 0.014 0.682 5.971\n", "C(site)[T.4] 3.5822 1.344 2.664 0.008 0.947 6.217\n", "C(site)[T.5] 3.5831 1.344 2.665 0.008 0.948 6.218\n", "C(site)[T.6] 3.8933 1.340 2.905 0.004 1.266 6.520\n", "C(site)[T.7] 4.7300 1.335 3.544 0.000 2.114 7.346\n", "C(site)[T.8] 5.5227 1.335 4.138 0.000 2.907 8.139\n", "C(site)[T.9] 6.7946 1.341 5.068 0.000 4.167 9.422\n", "==================================================================================\n" ] } ], "source": [ "model1 = sm.GLM.from_formula(\"blotch ~ 0 + C(variety) + C(site)\",\n", " family=sm.families.Binomial(), data=df)\n", "result1 = model1.fit(scale=\"X2\")\n", "print(result1.summary())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The plot below shows that the default variance function is\n", "not capturing the variance structure very well. Also note\n", "that the scale parameter estimate is quite small." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:50.782390Z", "iopub.status.busy": "2021-02-02T06:54:50.780954Z", "iopub.status.idle": "2021-02-02T06:54:51.016812Z", "shell.execute_reply": "2021-02-02T06:54:51.017897Z" }, "lines_to_next_cell": 1 }, "outputs": [ { "data": { "text/plain": [ "Text(0, 0.5, 'Residual')" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEGCAYAAAB7DNKzAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAnA0lEQVR4nO3de5hddX3v8feXYWIGBhgu7UiG2KCF1CBiygAWTuvESwOoJEWpokWx2py04sFbNAGpWtpDbNSW81RLU8oB0ToKpEOUSFRg0xYMhRBCCGkgB2vIhFPlMuCQoZmEb//Yayd7dtZe+74ue39ez5Nn9rrsvX6/nZn1Xb+7uTsiIiLlHJR0AkREJN0UKEREJJIChYiIRFKgEBGRSAoUIiIS6eCkE9AKxxxzjM+aNavu97/44osceuihzUtQiihv2dXO+VPekrd+/fqn3f1Xwo61ZaCYNWsWDzzwQN3vz+VyDA0NNS9BKaK8ZVc75095S56Z/azcsUSrnszsOjP7uZk9Uua4mdn/MbNtZvawmf1m3GkUEel0SbdRXA+cHXH8HOCE4N8i4G9jSJOIiBRJNFC4+z8Dz0acsgD4huetA/rM7Nh4UiciIpD+NooB4Mmi7R3BvqdKTzSzReRLHfT395PL5eq+6Pj4eEPvTzPlLbvaOX/KW7qlPVBYyL7QyancfSWwEmBwcNAbaTzKSuNTPZS37Grn/Clv6Zb2QLEDmFm0fRywM6G0iKTSyIZRVqzdys6xCWb09bBk/mwWzh1IOlnSRpJuzK5kNfCBoPfTG4Hn3f2AaieRTjWyYZRlqzYxOjaBA6NjEyxbtYmRDaNJJ03aSNLdY78N/ASYbWY7zOzDZrbYzBYHp6wBngC2AX8P/ElCSRVJpRVrtzIxuXfKvonJvaxYuzWhFEk7SrTqyd0vrHDcgY/GlByRzNk5NlHTfpF6pL3qSUQizOjrqWm/SD0UKEQybMn82fR0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rlE6hQCGdalXwcz0wK3j9u8DrzezdwfYRwAnk54z632b2O8DL5KfC7g/O+Zm7r4u4zreLfv5V0f6bgiDRC5wJ3BRMywH5aTogPw3Eu4LXN5K/2Zd6K3BNofrK3Z8NOec0IFeY9NHMvgX8Dvk5v/aSn91UpCwFCulU/xX83Mv+vwMDPubua4tPNLOLgV8BTnX3yaD+f3pw+MUK1/EyrwvvOwgYC1ZSrPT+MFblOeW8pHYJqURtFCL7rQX+OJgeGjM70cwOJV+y+HkQJOYBv1bDZ76n6OdPSg8GaxT81MwuCK5pZnZKcPge8jOqAry/zOf/EFgcTF6JmR0V7P8lcFjw+j7gTWZ2jOWXH70QuLuGPEiHU6CQdnSIme0o+vfJKt93LfAo8GDQWPx35Esb3wIGzewB8jfsf68hLa8IGoovBT5R5pz3Ax82s43AZvYvB3op+bWW7ycfrMqleTvwcPD+9wX7VwI/MLO73P0p8is03gVsBB4sLIIkUg11jxVpkXq6qIqkkUoUIiISSSUKERGJpBKFiIhEUqAQEZFIChQiIhJJgUJERCIpUIiISKT/BlTTC9AX5FOpAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "plt.clf()\n", "plt.grid(True)\n", "plt.plot(result1.predict(linear=True), result1.resid_pearson, 'o')\n", "plt.xlabel(\"Linear predictor\")\n", "plt.ylabel(\"Residual\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An alternative variance function is mu^2 * (1 - mu)^2." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:51.022657Z", "iopub.status.busy": "2021-02-02T06:54:51.021131Z", "iopub.status.idle": "2021-02-02T06:54:51.027933Z", "shell.execute_reply": "2021-02-02T06:54:51.028907Z" }, "lines_to_next_cell": 1 }, "outputs": [], "source": [ "class vf(sm.families.varfuncs.VarianceFunction):\n", " def __call__(self, mu):\n", " return mu**2 * (1 - mu)**2\n", "\n", " def deriv(self, mu):\n", " return 2*mu - 6*mu**2 + 4*mu**3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fit the quasi-binomial regression with the alternative variance\n", "function." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:51.033503Z", "iopub.status.busy": "2021-02-02T06:54:51.032053Z", "iopub.status.idle": "2021-02-02T06:54:51.160002Z", "shell.execute_reply": "2021-02-02T06:54:51.160950Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Generalized Linear Model Regression Results \n", "==============================================================================\n", "Dep. Variable: blotch No. Observations: 90\n", "Model: GLM Df Residuals: 72\n", "Model Family: Binomial Df Model: 17\n", "Link Function: logit Scale: 0.98855\n", "Method: IRLS Log-Likelihood: -21.335\n", "Date: Tue, 02 Feb 2021 Deviance: 7.2134\n", "Time: 06:54:51 Pearson chi2: 71.2\n", "No. Iterations: 25 \n", "Covariance Type: nonrobust \n", "==================================================================================\n", " coef std err z P>|z| [0.025 0.975]\n", "----------------------------------------------------------------------------------\n", "C(variety)[1] -7.9224 0.445 -17.817 0.000 -8.794 -7.051\n", "C(variety)[2] -8.3897 0.445 -18.868 0.000 -9.261 -7.518\n", "C(variety)[3] -7.8436 0.445 -17.640 0.000 -8.715 -6.972\n", "C(variety)[4] -6.9683 0.445 -15.672 0.000 -7.840 -6.097\n", "C(variety)[5] -6.5697 0.445 -14.775 0.000 -7.441 -5.698\n", "C(variety)[6] -6.5938 0.445 -14.829 0.000 -7.465 -5.722\n", "C(variety)[7] -5.5823 0.445 -12.555 0.000 -6.454 -4.711\n", "C(variety)[8] -4.6598 0.445 -10.480 0.000 -5.531 -3.788\n", "C(variety)[9] -4.7869 0.445 -10.766 0.000 -5.658 -3.915\n", "C(variety)[10] -4.0351 0.445 -9.075 0.000 -4.907 -3.164\n", "C(site)[T.2] 1.3831 0.445 3.111 0.002 0.512 2.255\n", "C(site)[T.3] 3.8601 0.445 8.681 0.000 2.989 4.732\n", "C(site)[T.4] 3.5570 0.445 8.000 0.000 2.686 4.428\n", "C(site)[T.5] 4.1079 0.445 9.239 0.000 3.236 4.979\n", "C(site)[T.6] 4.3054 0.445 9.683 0.000 3.434 5.177\n", "C(site)[T.7] 4.9181 0.445 11.061 0.000 4.047 5.790\n", "C(site)[T.8] 5.6949 0.445 12.808 0.000 4.823 6.566\n", "C(site)[T.9] 7.0676 0.445 15.895 0.000 6.196 7.939\n", "==================================================================================\n" ] } ], "source": [ "bin = sm.families.Binomial()\n", "bin.variance = vf()\n", "model2 = sm.GLM.from_formula(\"blotch ~ 0 + C(variety) + C(site)\", family=bin, data=df)\n", "result2 = model2.fit(scale=\"X2\")\n", "print(result2.summary())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With the alternative variance function, the mean/variance relationship\n", "seems to capture the data well, and the estimated scale parameter is\n", "close to 1." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-02-02T06:54:51.165268Z", "iopub.status.busy": "2021-02-02T06:54:51.163984Z", "iopub.status.idle": "2021-02-02T06:54:51.362613Z", "shell.execute_reply": "2021-02-02T06:54:51.363004Z" } }, "outputs": [ { "data": { "text/plain": [ "Text(0, 0.5, 'Residual')" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEGCAYAAABsLkJ6AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAffUlEQVR4nO3df5xddX3n8dcnYUImjDj8atqMYKBKFAgyy0AtbOsMZRssFqZYRbRWtrZZumoBMW2AVX5ol9AI2MeubaUV6bI8GvkZVJSgwNgWCpKQQIAYtFLQiV2FdIQJEzMkn/3j3hsmk3vnnnvvOed7fryfj0cemTlz55zv99y538/5/jZ3R0REymdW6ASIiEgYCgAiIiWlAC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f8kwzgaWI9nH3E83st4DLqCzk92EqazqdYGb7Ag+a2b1UVqv8HXd/ySqbyTxsZrXlChYB/9Xd/3uD67xUvc7vA58D3lU9fiRwqrvvNLP7gPPc/Xtm9ivAX1FZjuMvgb929/9jZh9pcP6lwOFAf3VW7YHuvtXMPg4MufsLZrYAuBo4HvgP4F4zG3b31cB+wJPu/qnWb6GUgQKAFNEd1f/XAQurX/8mcKyZ/W71+9cDb6ayftD/NLNfB3ZRWa54fvU1z7n7wzNc5x+m/H/dlOO3Vgv/HuAk4Nbqkg5QWeIBKssJvLv69U1UCvHpTgX+ptaM5O5b67zmBGCktqCfmd0M/DqVdZ92UlmtUqQuBQApop9X/9/Ja3/jBnzM3ddMfaGZnQscAhzv7pPV9vW51R9va3Idb/B17fdmAWPVneWa/X49FvE1jWxXu7/MRH0AUhZrgD+uLuOLmR1pZvtRqQn8pFr4DwFvbOGcZ0/5/1+m/7C6RvyzZvae6jXNzN5W/fGDVFbHBPhAg/PfC5xXXZQQMzuwevxl4HXVrx8B3mFmB1tlC8ZzgG+3kAcpMQUAyZt5ZvajKf8+HvH3/g54Gnis2sn6BSq1g5uBATNbS6Ug/m4Ladm32sF6PnBhg9d8APiwmT0OPMVrWyKeT2Uv2UepBKFGaX4eeKL6+++vHr8e+IaZPeDuP6ayY90DwOPAY7UNZUSa0TBQkTa0MxRTJGtUAxARKSnVAERESko1ABGRklIAEBEpKQUAEZGSUgAQESkpBQARkZL6/wd+wHhyK/nXAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "plt.clf()\n", "plt.grid(True)\n", "plt.plot(result2.predict(linear=True), result2.resid_pearson, 'o')\n", "plt.xlabel(\"Linear predictor\")\n", "plt.ylabel(\"Residual\")" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" }, "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.9" } }, "nbformat": 4, "nbformat_minor": 2 }