605:discussion

Jie Zou

2021-10-15

ex.3 pg289

let \(X_1\) and \(X_2\) be independent random variables with common distribution \[px = (\begin{matrix} 0 & 1 & 2\\1/8&3/8&1/2 \end{matrix})\] find the distrubution of the sum \(X_1+X_2.\)

let \(P_z = P(X_1 + X_2)\)

px1_0 = px2_0 = 1/8
px1_1 = px2_1 = 3/8
px1_2 = px2_2 = 1/2

\(P_z(0) = P_{X_1}(0)*P_{X_2}(0)\)

pz_0 = px1_0*px2_0
pz_0
## [1] 0.015625

\(P_z(1) = P_{X_1}(0)*P_{X_2}(1) + P_{X_1}(1)*P_{X_2}(0)\)

pz_1 = px1_0*px2_1 + px1_1*px2_0
pz_1
## [1] 0.09375

\(P_z(2) = P_{X_1}(0)*P_{X_2}(2) + P_{X_1}(1)*P_{X_2}(1)+P_{X_1}(2)*P_{X_2}(0)\)

pz_2 = px1_0*px2_2 + px1_1*px2_1 + px1_2*px2_0
pz_2
## [1] 0.265625

\(P_z(3) = P_{X_1}(1)*P_{X_2}(2) + P_{X_1}(2)*P_{X_2}(1)\)

pz_3 = px1_1*px2_2 + px1_2*px2_1
pz_3
## [1] 0.375

\(P_z(4) = P_{X_1}(2)*P_{X_2}(2)\)

pz_4 = px1_2*px2_2
pz_4
## [1] 0.25
# check the sum of pz
sum(pz_0,pz_1,pz_2,pz_3,pz_4)
## [1] 1

plot distribution

library(ggplot2)

data = c(pz_0,pz_1,pz_2,pz_3,pz_4)

barplot(data,xlim = c(0,6), ylab = "probability",xlab = 'pz', main = "the distribution of pz")