#PPT page 19
set.seed(123)
sort(sample(3:18, size=16, replace=F, prob=c(1/216, 3/216, 6/216, 10/216, 15/216, 21/216, 25/216, 27/216, 27/216, 25/216, 21/216, 15/216, 10/216, 6/216, 3/216, 1/216)))
## [1] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#we can see all possible sums from rolling three dice using R
dicea <- sample(1:6, 1000, T)
diceb <- sample(1:6, 1000, T)
dicec <- sample(1:6, 1000, T)
hist(dicea+diceb+dicec)
#Histogram for the sum of three dice (1000 frequence)
#the polt is empirical histogram
#PPT page 30
twodice <- outer(1:6, 1:6,'+')
twodice
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 2 3 4 5 6 7
## [2,] 3 4 5 6 7 8
## [3,] 4 5 6 7 8 9
## [4,] 5 6 7 8 9 10
## [5,] 6 7 8 9 10 11
## [6,] 7 8 9 10 11 12
#we can see all possible sums from rolling two dice using R
dice_countA <- table(twodice)
dice_countA
## twodice
## 2 3 4 5 6 7 8 9 10 11 12
## 1 2 3 4 5 6 5 4 3 2 1
threedice<- outer(2:12, 1:6,'+')
threedice
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 3 4 5 6 7 8
## [2,] 4 5 6 7 8 9
## [3,] 5 6 7 8 9 10
## [4,] 6 7 8 9 10 11
## [5,] 7 8 9 10 11 12
## [6,] 8 9 10 11 12 13
## [7,] 9 10 11 12 13 14
## [8,] 10 11 12 13 14 15
## [9,] 11 12 13 14 15 16
## [10,] 12 13 14 15 16 17
## [11,] 13 14 15 16 17 18
#we can see all possible sums from rolling three dice using R
dice_count <- table(threedice)
dice_count
## threedice
## 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## 1 2 3 4 5 6 6 6 6 6 6 5 4 3 2 1
#but the Frequence is False because I use "sum of 2 dice" add 1 dice
hist(threedice)