# Conditional Probability - Regions & Wealth

> This document is written in *R*.
>
> ***GitHub***: https://github.com/czs108

## Background

> The following table gives the *mean wealth* and *percentage population* in various *regions* of a fictitious country.
>
> |   Region   | Ashire | Bshire | Cshire | West Toptown | East Toptown | South Toptown | North Toptown |
> | :--------: | :----: | :----: | :----: | :----------: | :----------: | :-----------: | :-----------: |
> | **Wealth** |   80   |  110   |  110   |      70      |     120      |      90       |      110      |
> |  **Pop**   |  15%   |  20%   |  20%   |     10%      |     10%      |      10%      |      15%      |


```R
wealth.all <- c(80, 110, 110, 70, 120, 90, 110)
probs.all <- c(0.15, 0.20, 0.20, 0.10, 0.10, 0.10, 0.15)
```

## Question A

> What are the *mean* and *variance* of the *wealth* for the *whole* country?


```R
mean.all <- sum(wealth.all * probs.all)
var.all <- sum(((wealth.all - mean.all) ^ 2) * probs.all)

print(sprintf("Mean = %.1f", mean.all), quote=FALSE)
print(sprintf("Variance = %.1f", var.all), quote=FALSE)
```

    [1] Mean = 100.5
    [1] Variance = 254.8


## Question B

> What are the *mean* and *variance* of the *wealth* for those who live in *Toptown*?

Make the probabilities add up to **1**.


```R
probs.tp <- probs.all[4:7]
probs.tp <- probs.tp / sum(probs.tp)

sum(probs.tp)
```


1



```R
wealth.tp <- wealth.all[4:7]

mean.tp <- sum(wealth.tp * probs.tp)
var.tp <- sum(((wealth.tp - mean.tp) ^ 2) * probs.tp)

print(sprintf("Mean = %.1f", mean.tp), quote=FALSE)
print(sprintf("Variance = %.1f", var.tp), quote=FALSE)
```

    [1] Mean = 98.9
    [1] Variance = 343.2


## Question C

> What is the probability of living in an area with $\text{mean wealth} > 100$ if you live in *Toptown*?

\begin{equation}
\begin{split}
P &= \frac{P(live\ in\ Toptown\, \cap\, wealth > 100)}{P(live\ in\ Toptown)} \\
    &= \frac{10\% + 15\%}{10\% + 10\% + 10\% + 15\%} \\
    &= \frac{25\%}{45\%}
\end{split}
\end{equation}

## Question D

> What is the probability that you live in *Toptown* given that you live in an area with $\text{mean wealth} > 100$?

\begin{equation}
\begin{split}
P &= \frac{P(live\ in\ Toptown\, \cap\, wealth > 100)}{P(wealth > 100)} \\
    &= \frac{10\% + 15\%}{20\% + 20\% + 10\% + 15\%} \\
    &= \frac{25\%}{65\%}
\end{split}
\end{equation}

85d4f2b62f2336005b847f0d6c76b9a2bd40d6e1
ipynb
Jupyter Notebook
exercises/Conditional Probability - Regions & Wealth.ipynb
czs108/Probability-Theory-Exercises
60c6546db1e7f075b311d1e59b0afc3a13d93229
MIT
exercises/Conditional Probability - Regions & Wealth.ipynb
czs108/Probability-Theory-Exercises
60c6546db1e7f075b311d1e59b0afc3a13d93229
MIT
exercises/Conditional Probability - Regions & Wealth.ipynb
czs108/Probability-Theory-Exercises
60c6546db1e7f075b311d1e59b0afc3a13d93229
MIT
2022-03-21T05:04:07.000Z
2022-03-21T05:04:07.000Z
Qwen/Qwen-72B
1. YES
2. YES