Skip to content

Commit 75ee2e2

Browse files
committed
add mean and variance for discrete distributions
1 parent 13e51a8 commit 75ee2e2

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lectures/cross_section.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ kernelspec:
1111
name: python3
1212
---
1313

14+
(heavy_tail)=
1415
# Heavy-Tailed Distributions
1516

1617
```{contents} Contents
@@ -207,7 +208,6 @@ even more extreme observations.
207208

208209
See, for example, {cite}`mandelbrot1963variation` or {cite}`rachev2003handbook`.
209210

210-
(heavy_tail)=
211211
### Other Data
212212

213213
The data we have just seen is said to be "heavy-tailed".

lectures/prob_dist.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ u = scipy.stats.randint(1, n+1)
105105
Here's the mean and variance
106106

107107
```{code-cell} ipython3
108-
u.mean()
108+
u.mean(), u.var()
109109
```
110110

111-
```{code-cell} ipython3
112-
u.var()
113-
```
111+
The formula for the mean is $(n+1)/2$, and the formula for the variance is $(n^2 - 1)/12$.
114112

115113
+++ {"user_expressions": []}
116114

@@ -178,14 +176,22 @@ The interpretation of $p(i)$ is: the number of successes in $n$ independent tria
178176

179177
(If $\theta=0.5$, this is "how many heads in $n$ flips of a fair coin")
180178

181-
Here's the PDF
179+
The mean and variance are
182180

183181
```{code-cell} ipython3
184182
n = 10
185183
θ = 0.5
186184
u = scipy.stats.binom(n, θ)
187185
```
188186

187+
```{code-cell} ipython3
188+
u.mean(), u.var()
189+
```
190+
191+
The formula for the mean is $n \theta$ and the formula for the variance is $n \theta (1-\theta)$.
192+
193+
Here's the PDF
194+
189195
```{code-cell} ipython3
190196
u.pmf(1)
191197
```
@@ -220,7 +226,7 @@ plt.show()
220226
Using `u.pmf`, check that our definition of the CDF given above calculates the same function as `u.cdf`.
221227
```
222228

223-
```{solution-start} mc_ex2
229+
```{solution-start} prob_ex2
224230
:class: dropdown
225231
```
226232

@@ -251,6 +257,18 @@ $$
251257

252258
The interpretation of $p(i)$ is: the number of events in a fixed time interval, where the events occur at a constant rate $\lambda$ and independently of each other.
253259

260+
The mean and variance are
261+
```{code-cell} ipython3
262+
λ = 2
263+
u = scipy.stats.poisson(λ)
264+
```
265+
266+
```{code-cell} ipython3
267+
u.mean(), u.var()
268+
```
269+
270+
The the expectation of Poisson distribution is $\lambda$ and the variance is also $\lambda$.
271+
254272
Here's the PMF
255273

256274
```{code-cell} ipython3
@@ -312,7 +330,7 @@ Perhaps the most famous distribution is the **normal distribution**, which has d
312330

313331
$$
314332
p(x) = \frac{1}{\sqrt{2\pi}\sigma}
315-
\exp \left( - \frac{x - \mu}{2 \sigma^2} \right)
333+
\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)
316334
$$
317335

318336
This distribution has two parameters, $\mu$ and $\sigma$.

0 commit comments

Comments
 (0)