ppois(3, lambda = 2)[1] 0.8571235
Three balanced coins are tossed independently. Let \(X\) represent the number of heads, and \(Y\) the amount of money won on a side bet in the following manner. If the first head occurs on the first toss, you win $1. If the first head occurs on tosses 2 or 3, you respectively win $2 or $3. If no head appears, you lose $1 (that is, you win -$1).
Define the joint pmf table of \(X\) and \(Y\).
Note how the \(\omega's\) map to the possible values of \(X\) and \(Y\):
| \(\omega\) | (X) | (Y) |
|---|---|---|
| HHH | 3 | 1 |
| HHT | 2 | 1 |
| HTH | 2 | 1 |
| HTT | 1 | 1 |
| THH | 2 | 2 |
| THT | 1 | 2 |
| TTH | 1 | 3 |
| TTT | 0 | -1 |
Hence the joint pmf \(p(x,y) = P(X=x, Y=y)\):
| \(x\) | \(y=-1\) | \(y=1\) | \(y=2\) | \(y=3\) |
|---|---|---|---|---|
| x=0 | \(1/8\) | 0 | 0 | 0 |
| x=1 | 0 | \(1/8\) | \(1/8\) | \(1/8\) |
| x=2 | 0 | \(2/8 = 1/4\) | \(1/8\) | 0 |
| x=3 | 0 | \(1/8\) | 0 | 0 |
What is the joint support (i.e., the values of \(x\) and \(y\) for which \(p(x,y)>0\))?
The \((x,y)\) pairs with \(p(x,y) > 0\):
\[ \{(0,-1), (1,1), (1,2), (1,3), (2,1), (2,2), (3,1)\}. \]
Another way to represent this:
\[\{y \in \{1,2,3\}; x \in \{0,1,2,3\}; x \leq y\} \cup (0,-1)\]
Find and interpret \(F(2,1)\).
\(F(2,1) = P(X \le 2, Y \le 1)\)
Include outcomes with \(Y \le 1\) (i.e. \(Y = -1, 1\)) and \(X \le 2\):
\[ P(0,-1) + P(1,1) + P(2,1) = \frac{1}{8} + \frac{1}{8} + \frac{2}{8} = \frac{1}{2}. \]
Interpretation:
There is a 50% chance that the number of heads is at most 2 and the side-bet payoff is at most $1.
Find the marginal CDFs.
\[F_X(x) = \begin{cases} 0 & x < 0 \\ 1/8 & 0 \leq x < 1\\ 4/8 & 1 \leq x <2 \\ 7/8 & 2 \leq 1 < 3 \\ 1 & x \geq 3 \end{cases}\]
\[F_Y(y) = \begin{cases} 0 & y < -1 \\ 1/8 & -1 \leq y < 1\\ 5/8 & 1 \leq y <2 \\ 7/8 & 2 \leq y < 3 \\ 1 & y \geq 3 \end{cases}\]
Find the marginal pmfs.
For \(X\):
| \(x\) | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| \(P(X=x)\) | \(1/8\) | \(3/8\) | \(3/8\) | \(1/8\) |
For \(Y\):
| \(y\) | -1 | 1 | 2 | 3 |
|---|---|---|---|---|
| \(P(Y=y)\) | \(1/8\) | \(1/2\) | \(1/4\) | \(1/8\) |
Find the conditional pmf \(p_{X|Y}(x|1) = P(X=x|Y=1)\).
The joint probabilities are:
The marginal \(p_Y(1) = 1/2\)
Thus:
| \(x\) | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| \(P(X=x \mid Y=1)\) | \(0\) | \(1/4\) | \(1/2\) | \(1/4\) |
What is the probability you obtained 2 or more heads, given that you won $1 on the side bet?
\[ P(X \ge 2 \mid Y=1) = P(X=2 \mid Y=1) + P(X=3 \mid Y=1) = \tfrac{1}{2} + \tfrac{1}{4} = \tfrac{3}{4}. \]
Of nine executives in a business firm, four are married, three have never married, and two are divorced. Three of the executives are to be selected for promotion. Let \(X\) denote the number of married executives and \(Y\) denote the number of never-married executives among the three selected for promotion. Assuming that the three are randomly selected from the nine available:
Define the joint pmf, both as a formula and using a two-way table. Make sure your formula accounts for the support!
\[p_{X,Y}(x,y)=P(X=x,Y=y) =\frac{\binom{4}{x}\,\binom{3}{y}\,\binom{2}{3-(x+y)}}{\binom{9}{3}},\\ 0\le x\le 3, 0\le y\le 3, 1\le x+y\le 3\]
Two-way table:
| \(xy\) | \(y=0\) | \(y=1\) | \(y=2\) | \(y=3\) |
|---|---|---|---|---|
| x=0 | \(0\) | \(\dfrac{1}{28}\) | \(\dfrac{1}{14}\) | \(\dfrac{1}{84}\) |
| x=1 | \(\dfrac{1}{21}\) | \(\dfrac{2}{7}\) | \(\dfrac{1}{7}\) | \(0\) |
| x=2 | \(\dfrac{1}{7}\) | \(\dfrac{3}{14}\) | \(0\) | \(0\) |
| x=3 | \(\dfrac{1}{21}\) | \(0\) | \(0\) | \(0\) |
Find and interpret \(F(1,3)\).
\[F(1,3)=P(X\le 1, Y \le 3) =\frac{1}{28}+\frac{1}{14}+\frac{1}{84}+\frac{1}{21}+\frac{2}{7}+\frac{1}{7} =0.595238.\]
The probability that one or fewer married executives is chosen and 3 or fewer never-married execs are chosen is \(\approx 0.5952\).
Find the marginal pmf of \(X\), and identify it as having a well-known form.
\[ P(X=x)=\frac{\binom{4}{x}\,\binom{5}{3-x}}{\binom{9}{3}},\qquad x=0,1,2,3, \] because selecting \(x\) married people and \(3-x\) non-married (never-married or divorced; total \(5\)) from 9 is a hypergeometric selection.
So \(X\sim HYPERGEO(N=9,r=4,n=3)\).
Find \(p_{X|Y}(x|2)\).
First compute \(P(Y=2)\): \[ P(Y=2)=p(0,2)+p(1,2)=\frac{1}{14}+\frac{1}{7}=\frac{3}{14}. \]
The only feasible \(x\) when \(Y=2\) are \(x=0\) or \(x=1\) (because \(x+y\le 3\)). Thus \[ p_{X\mid Y}(0\mid 2)=\frac{p(0,2)}{P(Y=2)}=\frac{\tfrac{1}{14}}{\tfrac{3}{14}}=\tfrac{1}{3}, \] \[ p_{X\mid Y}(1\mid 2)=\frac{p(1,2)}{P(Y=2)}=\frac{\tfrac{1}{7}}{\tfrac{3}{14}}=\tfrac{2}{3}. \]
(Other \(x\) have conditional probability \(0\).)
| \(x\) | \(0\) | \(1\) |
|---|---|---|
| \(p_{X\mid Y}(x\mid 2)\) | \(1/3\) | \(2/3\) |
What is \(P(X=1|Y=2)\)?
From above, this is 2/3.
\(X\) and \(Y\) are discrete random variables indicating loss. They have a joint pmf given by:
\[p(x,y)=\frac{y}{24x};x=1,2,4;y=2,4,8;x \leq y\]
Verify that this is a valid pmf.
\[\begin{aligned} \sum p(x,y) &= \frac{1}{12}+\frac{1}{6}+\frac{1}{3}+\frac{1}{24}+\frac{1}{12}+\frac{1}{6}+\frac{1}{24}+\frac{1}{12}\\ &= \frac{2+4+8+1+2+4+1+2}{24}=\frac{24}{24}=1. \end{aligned}\]
An insurance policy pays the full amount of loss \(X\) and half of loss \(Y\). Find the probability that the total paid by the insurer is 5 or less.
Let \(T=X+\tfrac{1}{2}Y\). Then:
\[ P(T\le5)= p(1,2) + p(1,4) + p(1,8) + p(2,2) + p(2,4) = \frac{1}{12}+\frac{1}{6}+\frac{1}{3}+\frac{1}{24}+\frac{1}{12} =\frac{17}{24}. \]
Suppose \(X\) and \(Y\) are jointly discrete random variables with joint pmf given by:
\[P(X=x, Y=y) = \frac{1}{nx}, x = 1,...,n,\ y = 1,...,x\]
If \(n=3\), write out the joint pmf table.
| x | y = 1 | y = 2 | y = 3 |
|---|---|---|---|
| x = 1 | 1/3 | 0 | 0 |
| x = 2 | 1/6 | 1/6 | 0 |
| x = 3 | 1/9 | 1/9 | 1/9 |
Find the marginal distribution of \(X\), and describe it qualitatively.
\[p_X(x) = \sum_{y=1}^{x} \frac{1}{nx} = \frac{x}{nx} = \frac{1}{n}, \quad x = 1,2,\dots,n.\] \(X\) is uniformly distributed over the integers \(1\) through \(n\).
Suppose \(X\) and \(Y\) are jointly discrete random variables with joint pmf given by:
\[P(X=x,Y=y) = \frac{x+1}{12}, \quad x = 0, 1, \quad y=0,1,2,3\]
Find the marginal distributions of \(X\) and \(Y\). Do either of them have well-known forms?
Marginal of \(X\):
\[p_X(x) = \sum_{y=0}^{3} \frac{x+1}{12} = 4 \cdot \frac{x+1}{12} = \frac{x+1}{3}, x = 0,1\] Note this implies \(p_X(0) = 1/3\), and \(p_X(1) = 2/3\), thus \(X\sim BERN(2/3)\).
\[p_Y(y) = \sum_{x=0}^{1} \frac{x+1}{12}= \frac{0+1}{12} + \frac{1+1}{12} = \frac{1}{12} + \frac{2}{12} = \frac{3}{12} = \frac{1}{4}, \quad y = 0,1,2,3\]
Thus \(Y\) is uniformly distributed over the integers 0 through 4.
\(X\) and \(Y\) are jointly discrete random variables with joint pmf given by:
\[P(X=x,Y=x)=\frac{1}{e^2 y!(x-y)!}, x=0,1,..., y=0,1,...,x\]
Show that marginally, \(X\sim POI(2)\).
\[p_X(x) = \sum_{y=0}^{x} \frac{1}{e^2 y!(x-y)!}= \frac{1}{e^2} \sum_{y=0}^{x} \frac{1}{y!(x-y)!} = \frac{1}{e^2} \cdot \frac{1}{x!} \sum_{y=0}^{x} \binom{x}{y}= \frac{1}{e^2} \cdot \frac{1}{x!} \sum_{y=0}^{x} \binom{x}{y} \left(\frac{1}{2}\right)^y \left(\frac{1}{2}\right)^{x-y}2^x\] \[= \frac{2^xe^{-2}}{x!} \cdot 1, \quad x = 0,1,2,...\] if we note the summand as a \(BIN(x,0.5)\) pmf summed over its support hence equaling 1.
Thus \(X\sim POI(2)\).
Show that \(Y|X=x \sim BIN(x, 0.5)\).
\[p_{Y|X}(y|x) = p(x,y)/p_X(x) = \frac{\frac{e^{-2}}{ y!(x-y)!}}{\frac{2^xe^{-2}}{x!}} = \frac{x!}{y!(x-y)!}\left(\frac{1}{2}\right)^x=\binom{x}{y}\left(\frac{1}{2}\right)^y \left(\frac{1}{2}\right)^{x-y},\quad y = 0,1,2,...,x\]
Thus \(Y|X=x\sim BIN(x,0.5)\).
Find \(F(3,4)\) and \(F(4,2)\) (hint: write R code for both; you may want to define a parameter grid involving x and y for finding the latter by summing joint probabilities.)
\[F(3,4) = P(X\leq 3, Y \leq 4) = P(X\leq 3),\] since \(F\) only accumulates probability up until \(Y=X\).
ppois(3, lambda = 2)[1] 0.8571235
Thus \(F(3,4)=\) 0.8571235.
\[F(4,2) = P(X\leq 4, Y \leq 2) \]
library(purrrfect)
library(tidyverse)
(parameters(~x,~y,
0:4, 0:2)
%>% mutate(p_x = dpois(x, 2),
p_y_given_x = dbinom(y,x,.5)
)
%>% mutate(joint = p_x * p_y_given_x)
%>% summarize('F(4,2)' = sum(joint))
)# A tibble: 1 × 1
`F(4,2)`
<dbl>
1 0.897
For questions 7 and 8, render your work using R Quarto and publish your rendered html on R Pubs. Submit a link to your published html.
Consider Question 1. Use purrrfect::replicate() to simulate 10,000 realizations of \((X,Y)\) pairs. Use this to answer the following.
getY <- \(flip) {
num_heads <- sum(flip=='H')
which_heads <- which(flip=='H')
Y <- ifelse(num_heads >0, min(which_heads), -1)
return(Y)
}
(many_roll_games <- replicate(10000, sample(c('H','T'), 3, replace=TRUE), .as = flips)
%>% mutate(X = map_int(flips, \(fl) sum(fl=='H')))
%>% mutate(Y = map_int(flips, \(fl) getY(fl)))
) %>% head# A tibble: 6 × 4
.trial flips X Y
<dbl> <list> <int> <int>
1 1 <chr [3]> 2 1
2 2 <chr [3]> 0 -1
3 3 <chr [3]> 1 3
4 4 <chr [3]> 1 1
5 5 <chr [3]> 2 1
6 6 <chr [3]> 1 3
Use summarizing and pivoting to create the simulated joint pmf table.
(many_roll_games
%>% summarize(cnt = n(), .by = c(X,Y))
%>% mutate(pct = cnt/10000)
%>% arrange(X,Y)
%>% pivot_wider(names_from = Y, values_from = pct,
id_cols = X, names_prefix = 'y=',
names_sort=TRUE)
)# A tibble: 4 × 5
X `y=-1` `y=1` `y=2` `y=3`
<int> <dbl> <dbl> <dbl> <dbl>
1 0 0.124 NA NA NA
2 1 NA 0.121 0.124 0.130
3 2 NA 0.249 0.120 NA
4 3 NA 0.132 NA NA
Create a plot of the jittered \((X,Y)\) pairs to visually approximate the simulated joint pmf.
ggplot(data = many_roll_games) +
geom_jitter(aes(x = X, y = Y), width=.1, height=.3, size = .1, alpha = .2) +
scale_x_continuous(breaks = 0:3) +
scale_y_continuous(breaks = -1:3) +
theme_classic(base_size = 20)Use filtering and summarizing to find the simulated \(p_{X|Y}(x|1)\).
(many_roll_games
%>% filter(Y==1)
%>% summarize(cnt = n(), .by = c(Y,X))
%>% mutate('P(X|Y=1)' = cnt/sum(cnt))
)# A tibble: 3 × 4
Y X cnt `P(X|Y=1)`
<int> <int> <int> <dbl>
1 1 2 2494 0.497
2 1 1 1212 0.241
3 1 3 1315 0.262
Consider Question 2. Use purrrfect::replicate() to simulate 10,000 realizations of \((X,Y)\) pairs. Use this to answer the following.
Use summarizing and pivoting to create the simulated joint pmf table.
exec_pool <- rep(c('married','never','divorced'), c(4,3,2))
(many_promotions <- replicate(10000, sample(exec_pool, 3, replace=FALSE), .as = promoted)
%>% mutate(X = map_int(promoted, \(p) sum(p=='married')))
%>% mutate(Y = map_int(promoted, \(p) sum(p=='never')))
) %>% head# A tibble: 6 × 4
.trial promoted X Y
<dbl> <list> <int> <int>
1 1 <chr [3]> 2 1
2 2 <chr [3]> 1 1
3 3 <chr [3]> 1 2
4 4 <chr [3]> 1 1
5 5 <chr [3]> 2 0
6 6 <chr [3]> 2 0
(many_promotions
%>% summarize(cnt = n(), .by = c(X,Y))
%>% mutate(pct = cnt/10000)
%>% pivot_wider(names_from = Y, values_from = pct,
id_cols = X, names_prefix = 'y=', names_sort=TRUE)
)# A tibble: 4 × 5
X `y=0` `y=1` `y=2` `y=3`
<int> <dbl> <dbl> <dbl> <dbl>
1 2 0.145 0.212 NA NA
2 1 0.0492 0.284 0.145 NA
3 3 0.0472 NA NA NA
4 0 NA 0.0346 0.0711 0.0116
create a plot of the jittered \((X,Y)\) pairs to visually approximate the simulated joint pmf.
ggplot(data = many_promotions) +
geom_jitter(aes(x = X, y = Y), width=.1, height=.3, size = .1, alpha = .2) +
scale_x_continuous(breaks = 0:3) +
scale_y_continuous(breaks = -1:3) +
theme_classic(base_size = 20)Use filtering and summarizing to find the simulated \(p_{X|Y}(x|2)\).
(many_promotions
%>% filter(Y==2)
%>% summarize(cnt = n(), .by = c(Y,X))
%>% mutate('P(X|Y=2)' = cnt/sum(cnt))
)# A tibble: 2 × 4
Y X cnt `P(X|Y=2)`
<int> <int> <int> <dbl>
1 2 1 1452 0.671
2 2 0 711 0.329