Simulating 2 die tosses with the probability of getting a 3 = 0.5;
```{r}
toss = function() {
outcomes = sample(x = c(1,2,3,4,5,6), size = 2, replace = TRUE, prob = c(0.1, 0.1, 0.5, 0.1, 0.1,0.1))
sum_dice = sum(outcomes)
sum_dice
}
```
The distribution of the sum of the outcomes is:
```{r}
set.seed(100000)
sum_dice = replicate(100000, toss())
sum = 2:12
Probability = c(mean(sum_dice == 2), mean(sum_dice == 3), mean(sum_dice == 4), mean(sum_dice == 5), mean(sum_dice == 6), mean(sum_dice == 7), mean(sum_dice == 8), mean(sum_dice == 9), mean(sum_dice == 10), mean(sum_dice == 11), mean(sum_dice == 22))
```
The sum_dice values are: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 with probabilities 0.01015, 0.01988, 0.10903, 0.12149, 0.29217, 0.1399, 0.13059, 0.1182, 0.02859, 0.02002, 0 respectively
```{r}
mean = mean(sum_dice)
variance = var(sum_dice)
```
The expectation is 6.59023 and variance 3.5938745.
Comments
Leave a comment