Riddler: Simulating and Optimizing Coin Flipping
Simulation
Notable topics: Simulation
Recorded on: 2020-05-02
Timestamps by: Alex Cookson
Screencast
Timestamps
Using crossing
function to set up "tidy" simulation (gives you all possible combinations of values you provide it)
Using rbinom
function to simulate the number of prisoners who choose to flip, then using rbinom
again to simulate number of tails
Using dbinom
function (probability mass function) to see probabilities of any given number of prisoners choosing to flip
Using map_dbl
function to iterate a function, making sure to return a dbl
-class object
Using seq_len(n)
instead of 1:n
to be slightly more efficient
Using optimise
function to conduct single-dimension optimisation (for analytical solution to this question)
Using backticks (like this
) for inline R functions in RMarkdown
Starting the Extra Credit portion of the problem (N prisoners instead of 4)
Using map2_dbl
function to iterate a function that requires two inputs (and make sure it returns a dbl
-class object)
Reviewing visualisation of probabilties with a varying numbers of prisoners
Tweaking graph to look nicer
Get the exact optimal probability value for each number of prisoners
Troubleshooting optimise
function to work when iterated over different numbers of prisoners
Using unnest_wider
function to disaggregate a list, but put different elements on separate columns (not separate rows, which unnest
does
Explanation of what happens to probabilities as number of prisoners increases
Summary of screencast