--- tags: introduction to probability, statistics --- # Expected Values ([home](https://github.com/alexhkurz/introduction-to-probability/blob/master/README.md) ... [next](https://hackmd.io/@alexhkurz/BkW-1p7aL)) (draft) ## Rolling two dice **Activity:** Roll the two dice 30 times and make a list of the outcomes. Which outcomes are most frequent? Draw a bar chart with columns for the possible outcomes from 2 to 12 and the height of the column indicating how often an outcome happened. This raises some interesting questions. For example: - Why appear some outcomes more often than others? - What would you expect from counting the possibilities? ## Expected values of two dice **Activity:** Make another bar chart with columns for the possible outcomes from 2 to 12 and the height of the column indicating how many possibilities there are to achieve that outcome. We call this the bar chart of **expected values**. More questions: - Should the two bar charts be the same? Or similar? Why are they so different? - What happens if we do the experiment again and do another 30 rolls of two dice? ## A program to roll dice This is getting a bit boring to do by hand, so I wrote a little program called [two-dice-1.R](https://github.com/alexhkurz/introduction-to-probability/blob/master/src/two-dice.R). You need to install R to run the program. number_of_rolls <- 30 die1_sample <- as_tibble(rdunif(number_of_rolls,1,6)) # all values from 1 to 6 are equally likely die2_sample <- as_tibble(rdunif(number_of_rolls,1,6)) two_dice <- die1_sample + die2_sample # add the values of the two dice two_dice %>% ggplot() + geom_bar(aes(x=value)) + scale_x_continuous(name = "two dice", breaks = 2:12) **Activity:** Run the program. Read the program line by line and try to find out what each line means. A good way to find out what each line in the program means is to change the lines, to execute the program again and to see what happens. Can you make a die that has more than 6 sides? ## Rolling dice large numbers of times Now we understand the program a bit better, we can use it to roll the two dice as often as we wish at the klick of a button.[^largenumbers] **Activity:** Run the program for different values of `number_of_rolls`. How large do you have to make `number_of_rolls` so that 7 is reliably the most frequent outcome? How large do you have to make `number_of_rolls` so that the bar chart produced by the program looks similar to the bar chart of expected values? ## Summary There are many possible questions here. Make a list with questions. - ... - ... - ... [^largenumbers]: "As often as you wish"? Maybe not quite. Find a value for `number_of_rolls` that is large enough to break `R` (or your patience).