p.289
Distribution of X
library(ggplot2)
X <- data.frame(list(num=c(0,1,2)), stringsAsFactors=FALSE)
ggplot(data = X,aes(x=X$num))+geom_histogram(aes(x=X$num,y=..density..),binwidth=1, color='red')
Distribution of Y
Y <- data.frame(list(num=c(3,4,4,4)), stringsAsFactors=FALSE)
ggplot(data = Y,aes(x=Y$num))+geom_histogram(aes(x=Y$num,y=..density..),binwidth=1, color='blue')
Distribution of X+Y
Z <- data.frame()
for (i in X$num){
for (j in Y$num){
Z <- rbind(Z, i+j)
}
}
Z
## X3
## 1 3
## 2 4
## 3 4
## 4 4
## 5 4
## 6 5
## 7 5
## 8 5
## 9 5
## 10 6
## 11 6
## 12 6
ggplot(data = Z,aes(x=Z))+geom_histogram(aes(x=Z,y=..density..),binwidth=1, color='green')
Distribution of Y- X Distribution of X+Y
Z <- data.frame()
for (i in X$num){
for (j in Y$num){
Z <- rbind(Z, j-i)
}
}
Z
## X3
## 1 3
## 2 4
## 3 4
## 4 4
## 5 2
## 6 3
## 7 3
## 8 3
## 9 1
## 10 2
## 11 2
## 12 2
ggplot(data = Z,aes(x=Z))+geom_histogram(aes(x=Z,y=..density..),binwidth=1, color='yellow')