## __Data 5600: Hwk1b__

<br>

### __Solutions__


---



```python
from scipy.stats import binom
```

<br>

#### <u>__Problem 3__</u>

<br>

<u>__Part a.__</u> We can use the CDF function to solve for this. Let $\theta$ be the probability that an engine works properly, then $q = 1 - \theta$.

- If $X$ is the random variable that represents how many out of $n$ engines work properly, then $X \sim Binomial(n, \theta)$

- For a four-engine plane this is:

<br>

$$
\begin{align}
P(X \ge 2) &= 1 - P(X < 2) \\
           &= 1 - P(X = 0) - P(X = 1) \\
           &= 1 - \binom{4}{0}\theta^{0} (1 - \theta)^{4} - \binom{4}{1}\theta(1 - \theta)^{3} \\
           &= 1 - (1-\theta)^{4} + 4 \theta (1 - \theta)^{3}
\end{align}
$$

<br>

If $\theta = 0.6$ then

<br>

$$
\begin{align}
1 - P(X = 0) - P(X = 1) &= 1 - (0.4)^{4} - 4 (0.6) (0.4)^{3} \\
                        &= 1 - 0.256 - 4 \ast 0.6 \ast 0.064 \\
                        &= 0.8208
\end{align}
$$

<br>


```python
## Set theta (the probability of success)
θ = 0.8

## Calculate directly from above
1. - (1-θ)**4 - 4 * (θ) * (1 - θ)**3
```




    0.9728




```python
## Calculate using the binomial pmf
1. - binom(n=4,p=θ).pmf(0) - binom(n=4, p=θ).pmf(1)
```




    0.9728




```python
## Use the complement of the CDF
1. - binom(n=4, p=θ).cdf(1)
```




    0.9728



<br>

<u>__Part b.__</u> For a two-engine plane $X \sim Binomial(2, \theta)$

<br>

$$
\begin{align}
P(X \ge 1) &= 1 - P(X = 0) \\
           &= 1 - \binom{2}{0} (1 - \theta)^{2}
\end{align}
$$

<br>


```python
## Set theta (the probability of success)
θ = 0.8

## Calculate directly from above
1. - (1 - θ)**2
```




    0.96




```python
## Calculate using the binomial pmf
1 - binom(n=2, p=θ).pmf(0)
```




    0.96




```python
## Calculate using the complement of the CDF
1 - binom(n=2, p=θ).cdf(0)
```




    0.96



<br>

<u>__Part c.__</u> Let's make a table to compare for different values of $\theta$

<br>

| <b>$\theta$</b> | 4 Engines | 2 Engines |
|:---------------:|:---------:|:---------:|
| 0.5             | 0.6865    |  0.7500   |
| 0.6             | 0.8208    |  0.8400   |
| 0.7             | 0.9163    |  0.9100   |
| 0.8             | 0.9728    |  0.9600   |

<br>

---

#### <u>__Problem 6__</u>

<br>


```python

```

b666351d9631aa6e14cd7aaa96faaca2528554d7
ipynb
Jupyter Notebook
Assignments/Hwk1/hwk1b-key.ipynb
CAIJedi/DATA-5600-FL21
df88e9462eb87c277e52966359638f07874b60fc
CC0-1.0
2021-11-11T00:21:39.000Z
2021-11-11T00:21:39.000Z
Assignments/Hwk1/hwk1b-key.ipynb
CAIJedi/DATA-5600-FL21
df88e9462eb87c277e52966359638f07874b60fc
CC0-1.0
Assignments/Hwk1/hwk1b-key.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