Skip to content

Commit 1d67b3e

Browse files
authored
Merge pull request #406 from QuantEcon/update_prob_dist_bernoulli
[prob_dist] Update Bernoulli distribution section
2 parents f55ce53 + c2c1c8e commit 1d67b3e

File tree

1 file changed

+18
-49
lines changed

1 file changed

+18
-49
lines changed

lectures/prob_dist.md

+18-49
Original file line numberDiff line numberDiff line change
@@ -155,74 +155,43 @@ Check that your answers agree with `u.mean()` and `u.var()`.
155155

156156
#### Bernoulli distribution
157157

158-
Another useful (and more interesting) distribution is the Bernoulli distribution
158+
Another useful distribution is the Bernoulli distribution on $S = \{0,1\}$, which has PMF:
159159

160-
We can import the uniform distribution on $S = \{1, \ldots, n\}$ from SciPy like so:
161-
162-
```{code-cell} ipython3
163-
n = 10
164-
u = scipy.stats.randint(1, n+1)
165-
```
160+
$$
161+
p(x_i)=
162+
\begin{cases}
163+
p & \text{if $x_i = 1$}\\
164+
1-p & \text{if $x_i = 0$}
165+
\end{cases}
166+
$$
166167

168+
Here $x_i \in S$ is the outcome of the random variable.
167169

168-
Here's the mean and variance
170+
We can import the Bernoulli distribution on $S = \{0,1\}$ from SciPy like so:
169171

170172
```{code-cell} ipython3
171-
u.mean(), u.var()
173+
p = 0.4
174+
u = scipy.stats.bernoulli(p)
172175
```
173176

174-
The formula for the mean is $(n+1)/2$, and the formula for the variance is $(n^2 - 1)/12$.
175-
176177

177-
Now let's evaluate the PMF
178+
Here's the mean and variance:
178179

179180
```{code-cell} ipython3
180-
u.pmf(1)
181+
u.mean(), u.var()
181182
```
182183

183-
```{code-cell} ipython3
184-
u.pmf(2)
185-
```
184+
The formula for the mean is $p$, and the formula for the variance is $p(1-p)$.
186185

187186

188-
Here's a plot of the probability mass function:
187+
Now let's evaluate the PMF:
189188

190189
```{code-cell} ipython3
191-
fig, ax = plt.subplots()
192-
S = np.arange(1, n+1)
193-
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
194-
ax.vlines(S, 0, u.pmf(S), lw=0.2)
195-
ax.set_xticks(S)
196-
plt.show()
197-
```
198-
199-
200-
Here's a plot of the CDF:
201-
202-
```{code-cell} ipython3
203-
fig, ax = plt.subplots()
204-
S = np.arange(1, n+1)
205-
ax.step(S, u.cdf(S))
206-
ax.vlines(S, 0, u.cdf(S), lw=0.2)
207-
ax.set_xticks(S)
208-
plt.show()
209-
```
210-
211-
212-
The CDF jumps up by $p(x_i)$ and $x_i$.
213-
214-
215-
```{exercise}
216-
:label: prob_ex2
217-
218-
Calculate the mean and variance for this parameterization (i.e., $n=10$)
219-
directly from the PMF, using the expressions given above.
220-
221-
Check that your answers agree with `u.mean()` and `u.var()`.
190+
u.pmf(0)
191+
u.pmf(1)
222192
```
223193

224194

225-
226195
#### Binomial distribution
227196

228197
Another useful (and more interesting) distribution is the **binomial distribution** on $S=\{0, \ldots, n\}$, which has PMF

0 commit comments

Comments
 (0)