|
4 | 4 | "cell_type": "markdown",
|
5 | 5 | "metadata": {},
|
6 | 6 | "source": [
|
7 |
| - "# GLM: Negative Binomial Regression\n", |
8 |
| - "\n", |
9 |
| - "This notebook demos negative binomial regression using the `glm` submodule. It closely follows the GLM Poisson regression example by [Jonathan Sedar](https://github.com/jonsedar) (which is in turn insipired by [a project by Ian Osvald](http://ianozsvald.com/2016/05/07/statistically-solving-sneezes-and-sniffles-a-work-in-progress-report-at-pydatalondon-2016/)) except the data here is negative binomially distributed instead of Poisson distributed.\n", |
10 |
| - "\n", |
11 |
| - "Negative binomial regression is used to model count data for which the variance is higher than the mean. The [negative binomial distribution](https://en.wikipedia.org/wiki/Negative_binomial_distribution) can be thought of as a Poisson distribution whose rate parameter is gamma distributed, so that rate parameter can be adjusted to account for the increased variance.\n", |
12 |
| - "\n", |
13 |
| - "#### Contents\n", |
14 |
| - "\n", |
15 |
| - "+ [Setup](#Setup)\n", |
16 |
| - " + [Convenience Functions](#Convenience-Functions)\n", |
17 |
| - " + [Generate Data](#Generate-Data)\n", |
18 |
| - " + [Poisson Data](#Poisson-Data)\n", |
19 |
| - " + [Negative Binomial Data](#Negative-Binomial-Data)\n", |
20 |
| - " + [Visualize the Data](#Visualize-the-Data)\n", |
21 |
| - "\n", |
22 |
| - "\n", |
23 |
| - "+ [Negative Binomial Regression](#Negative-Binomial-Regression)\n", |
24 |
| - " + [Create GLM Model](#Create-GLM-Model)\n", |
25 |
| - " + [View Results](#View-Results)\n" |
26 |
| - ] |
27 |
| - }, |
28 |
| - { |
29 |
| - "cell_type": "markdown", |
30 |
| - "metadata": {}, |
31 |
| - "source": [ |
32 |
| - "## Setup" |
| 7 | + "# GLM: Negative Binomial Regression" |
33 | 8 | ]
|
34 | 9 | },
|
35 | 10 | {
|
36 | 11 | "cell_type": "code",
|
37 | 12 | "execution_count": 1,
|
38 |
| - "metadata": { |
39 |
| - "scrolled": true |
40 |
| - }, |
41 |
| - "outputs": [], |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [ |
| 15 | + { |
| 16 | + "name": "stderr", |
| 17 | + "output_type": "stream", |
| 18 | + "text": [ |
| 19 | + "/home/osvaldo/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", |
| 20 | + " from ._conv import register_converters as _register_converters\n" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "name": "stdout", |
| 25 | + "output_type": "stream", |
| 26 | + "text": [ |
| 27 | + "Running on PyMC3 v3.3\n" |
| 28 | + ] |
| 29 | + } |
| 30 | + ], |
42 | 31 | "source": [
|
| 32 | + "%matplotlib inline\n", |
43 | 33 | "import numpy as np\n",
|
44 | 34 | "import pandas as pd\n",
|
45 | 35 | "import pymc3 as pm\n",
|
46 | 36 | "from scipy import stats\n",
|
47 |
| - "from scipy import optimize\n", |
48 | 37 | "import matplotlib.pyplot as plt\n",
|
| 38 | + "plt.style.use('seaborn-darkgrid')\n", |
49 | 39 | "import seaborn as sns\n",
|
50 | 40 | "import re\n",
|
| 41 | + "print('Running on PyMC3 v{}'.format(pm.__version__))" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "markdown", |
| 46 | + "metadata": {}, |
| 47 | + "source": [ |
| 48 | + "This notebook demos negative binomial regression using the `glm` submodule. It closely follows the GLM Poisson regression example by [Jonathan Sedar](https://github.com/jonsedar) (which is in turn inspired by [a project by Ian Osvald](http://ianozsvald.com/2016/05/07/statistically-solving-sneezes-and-sniffles-a-work-in-progress-report-at-pydatalondon-2016/)) except the data here is negative binomially distributed instead of Poisson distributed.\n", |
51 | 49 | "\n",
|
52 |
| - "%matplotlib inline" |
| 50 | + "Negative binomial regression is used to model count data for which the variance is higher than the mean. The [negative binomial distribution](https://en.wikipedia.org/wiki/Negative_binomial_distribution) can be thought of as a Poisson distribution whose rate parameter is gamma distributed, so that rate parameter can be adjusted to account for the increased variance." |
53 | 51 | ]
|
54 | 52 | },
|
55 | 53 | {
|
|
246 | 244 | {
|
247 | 245 | "cell_type": "code",
|
248 | 246 | "execution_count": 6,
|
249 |
| - "metadata": {}, |
| 247 | + "metadata": { |
| 248 | + "collapsed": true |
| 249 | + }, |
250 | 250 | "outputs": [],
|
251 | 251 | "source": [
|
252 | 252 | "# Gamma shape parameter\n",
|
|
670 | 670 | "name": "python",
|
671 | 671 | "nbconvert_exporter": "python",
|
672 | 672 | "pygments_lexer": "ipython3",
|
673 |
| - "version": "3.5.2" |
| 673 | + "version": "3.6.3" |
674 | 674 | }
|
675 | 675 | },
|
676 | 676 | "nbformat": 4,
|
|
0 commit comments