St Petesburg Paradox

Fernando Crema

The game itself

You need to throw a coin.

  1. If you get heads, you lose and earn 2i money being i the number of times the coin was flipped.
  2. If you get tail, you continue playing and do i = i + 1.
  • Mathematician Bernoulli discovered this game in 17th century
  • The expected value of the income the player wins is infinite.
  • This is a paradox!!!

The code

I first set the ui.R in which I put only 2 slider inputs.

sliderInput("n_bank", "How much the Casino is charging to play", value = 500, min = 10, max = 10000)

The slider for the input is similar          

The paradox has 2 points of view:
- The player (how much you'll pay to play)
- The Casino (how much you'll charge to let them play)


The Plot

The app has a plot in which:

  • the X axis is the money you won in a round
  • the Y axis is the numbers of times you actually won that in a round

The plot is in the server.R section in the line

    output$plot <- renderPlot({
        plot(tabla())
    })

    ```

Example

Using 10.000 experiments this is the output plot of chunk unnamed-chunk-1

The summary

This is the fun part:

You'll need to change the sliders in order to have a “winnable” setup.

  • We know the expected value of winning is infinite but: is this really true?
  • The summary will simple substract the money you won and the money the casino charged you to play the game.

Example with 25$ charge of bank and 10000 time played (don't play if the bank charge 25$ ;))

[1] "You won 128776 and you paid 250000 final money -121224"

The Table

In this part I only show the table of the current game.

  • outcome is the amount of money you won in 1 round.
  • freq is the number of rounds that matched this money
   outcome Freq
1        2 4962
2        4 2499
3        8 1293
4       16  661
5       32  304
6       64  148
7      128   69
8      256   24
9      512   23
10    1024    7
11    2048    5
12    4096    4
13    8192    1