Skip to content

Commit f4a7ed1

Browse files
committed
making requested adjustments
1 parent fbc0baa commit f4a7ed1

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

docs/notebooks/negative_binomial.ipynb

+5-13
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,28 @@
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
21-
"The negative binomial distribution is flexible with multiple possible formulations. For example, it can model the number of *trials* or *failures* in a sequence of independent Bernoulli trials with probability of success (or failure) $p$ until the $k$-th \"success\". If we want to model the number of trials until the $k$-th success, we can use the following definition:\n",
21+
"The negative binomial distribution is flexible with multiple possible formulations. For example, it can model the number of *trials* or *failures* in a sequence of independent Bernoulli trials with probability of success (or failure) $p$ until the $k$-th \"success\". If we want to model the number of trials until the $k$-th success, the probability mass function (pmf) results:\n",
2222
"\n",
2323
"$$\n",
24-
"Y \\sim \\text{NB}(k, p)\n",
24+
"p(y | k, p)= \\binom{y - 1}{y-k}(1 -p)^{y - k}p^k\n",
2525
"$$\n",
2626
"\n",
2727
"where $0 \\le p \\le 1$ is the probability of success in each Bernoulli trial, $k > 0$, usually integer, $y \\in \\{k, k + 1, \\cdots\\}$ and $Y$ is the number of trials until the $k$-th success.\n",
2828
"\n",
29-
"The probability mass function (pmf) is \n",
30-
"\n",
31-
"$$\n",
32-
"p(y | k, p)= \\binom{y - 1}{y-k}(1 -p)^{y - k}p^k\n",
33-
"$$\n",
34-
"\n",
3529
"In this case, since we are modeling the number of *trials* until the $k$-th success, $y$ starts at $k$ and can be any integer greater than or equal to $k$. If instead we want to model the number of *failures* until the $k$-th success, we can use the same definition but $Y$ represents failures and starts at $0$ and there's a slightly different pmf:\n",
3630
"\n",
3731
"$$\n",
3832
"p(y | k, p)= \\binom{y + k - 1}{k-1}(1 -p)^{y}p^k\n",
3933
"$$\n",
4034
"\n",
41-
"In this case, $y$ starts at $0$ and can be any integer greater than or equal to $0$. When modeling failures, $y$ starts at 0, when modeling trials, $y$ starts at $k$.\n",
42-
"\n",
43-
"\n"
35+
"In this case, $y$ starts at $0$ and can be any integer greater than or equal to $0$. When modeling failures, $y$ starts at 0, when modeling trials, $y$ starts at $k$."
4436
]
4537
},
4638
{
4739
"cell_type": "markdown",
4840
"metadata": {},
4941
"source": [
50-
"These are not the only ways of defining the negative binomial distribution, there are plenty of options! One of the most interesting, and the one you see in [PyMC3](https://docs.pymc.io/api/distributions/discrete.html#pymc3.distributions.discrete.NegativeBinomial), the library we use in Bambi for the backend, is as a continuous mixture. The negative binomial distribution describes a Poisson random variable whose rate is also a random variable (not a fixed constant!) following a gamma distribution. Or in other words, conditional on a gamma-distributed variable $\\mu$, the variable $Y$ has a Poisson distribution with mean $\\mu$.\n",
42+
"These are not the only ways of defining the negative binomial distribution, there are plenty of options! One of the most interesting, and the one you see in [PyMC](https://www.pymc.io/projects/docs/en/stable/api/distributions/generated/pymc.NegativeBinomial.html), the library we use in Bambi for the backend, is as a continuous mixture. The negative binomial distribution describes a Poisson random variable whose rate is also a random variable (not a fixed constant!) following a gamma distribution. Or in other words, conditional on a gamma-distributed variable $\\mu$, the variable $Y$ has a Poisson distribution with mean $\\mu$.\n",
5143
"\n",
5244
"Under this alternative definition, the pmf is\n",
5345
"\n",
@@ -96,7 +88,7 @@
9688
"cell_type": "markdown",
9789
"metadata": {},
9890
"source": [
99-
"Scipy uses the number of *failures* until $k$ successes definition, therefore $y$ starts at 0. In the following plot, we have the probability of observing $y$ failures before we see $k=3$ successes. "
91+
"SciPy uses the number of *failures* until $k$ successes definition, therefore $y$ starts at 0. In the following plot, we have the probability of observing $y$ failures before we see $k=3$ successes. "
10092
]
10193
},
10294
{

0 commit comments

Comments
 (0)