# DATA 5600: Introduction to Regression and Machine Learning for Analytics

## __CLT Examples__ <br>

Author:      Tyler J. Brough <br>
Updated: October 6, 2021 <br>

---

<br>


```python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
```

### __Probability Distribution, Mean, and Variance of a Poisson Random Variable__

---

$$
\begin{align}
p(x) &= \frac{\lambda^{x} e^{-\lambda}}{x!} \quad x = 0, 2, \ldots \\
     & \\
\mu  &= \lambda \\
     & \\
\sigma^{2} &= \lambda \\
\end{align}
$$

---

<br>

where

* $\lambda =$ mean number of events during given unit of time, area, volume, etc.

* $e = 2.71828...$

<br>
<br>


<br>

#### __Poisson Example__

<br>
<br>

Suppose the number, $x$, of a company's employees who are absent on Mondays has (approximately) a Poisson probability distribution. Further, assume that the average number of Monday absentees is 2.6.

<br>

* (a) Find the mean and standard deviation of $x$ the number of employees absent on Monay. 


$$
\begin{align}
\mu &= \lambda = 2.6 \\
& \\
\sigma^{2} &= \lambda = 2.6
\end{align}
$$

Then the standard deviation is: $\sqrt{2.6} = 1.61$

<br>


```python
λ = 2.6
n = 52 # weeks 
x = np.random.poisson(lam=λ, size=n)
```


```python
x
```




    array([0, 1, 3, 3, 6, 2, 1, 4, 3, 5, 3, 7, 1, 2, 4, 1, 1, 3, 1, 1, 3, 4,
           5, 1, 2, 5, 2, 5, 2, 2, 3, 3, 1, 1, 4, 6, 2, 3, 2, 0, 4, 1, 1, 1,
           2, 2, 3, 4, 1, 1, 2, 2])




```python
xbar = np.mean(x)
xbar
```




    2.5384615384615383




```python
sbar = np.std(x, ddof=1)
sbar
serr = sbar / np.sqrt(n)
```


```python
z = (x - xbar) / sbar
```


```python
M = 500_000
n = 104

xbars = np.zeros(M)

for i in range(M):
    xbars[i] = np.mean(np.random.poisson(lam=λ, size=n))
```


```python
plt.hist(xbars, bins=25)
```


```python
zbars = (xbars - λ) / (np.sqrt(λ) / np.sqrt(n))
```


```python
plt.hist(zbars)
```


```python
np.mean(zbars)
```




    -0.000184020234609593




```python
np.std(zbars,ddof=1)
```




    1.000616162076678




```python

```

b530ecceba2b7940ac002b163d0723de517a7148
ipynb
Jupyter Notebook
Lectures/Gelman et al/Chapter04/Untitled2.ipynb
CAIJedi/DATA-5600-FL21
df88e9462eb87c277e52966359638f07874b60fc
CC0-1.0
2021-11-11T00:21:39.000Z
2021-11-11T00:21:39.000Z
Lectures/Gelman et al/Chapter04/Untitled2.ipynb
CAIJedi/DATA-5600-FL21
df88e9462eb87c277e52966359638f07874b60fc
CC0-1.0
Lectures/Gelman et al/Chapter04/Untitled2.ipynb
CAIJedi/DATA-5600-FL21
df88e9462eb87c277e52966359638f07874b60fc
CC0-1.0
2021-09-15T19:40:06.000Z
2021-11-09T02:48:36.000Z
Qwen/Qwen-72B
1. YES
2. YES