Winning from losing

By following twitter’s #rstats hashtag (rss feed), I recently came across a very interesting R-related blog: datanalytics.com.

The first post I read from it was about setting up an on-line reading group to go through the excellent “The Elements of Statistical Learning“. It is going on and you can find related posts here. Something you should know, however: it’s in Spanish.

Thanks to that blog, I’ve learned at least one thing: the meaning of ‘L’ as in x<-10L, which I've seen in some code before but never investigated further. It turns out that it's used to cast variables as integers instead of doubles. You can see that in their code, which also has other unexpected examples:

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
a <- 1:10
typeof( a )
object.size( a )
 
a[1] <- 10
typeof( a )
object.size( a )
 
a <- 1:10
a[1] <- 10L
typeof( a )
object.size( a )

The blog also presented a puzzle last week. The gist of it is that you play three different gambling games:

  • Game 1: at each step, you win 1 point with probability 0.49 and lose 1 point with probability 0.51.
  • Game 2: at each step, you look at how many points you have accumulated so far. If it's a multiple of 3, you win 1 point with probability 0.095 and lose 1 point with probability 0.905. Otherwise, you win 1 point with probability 0.745 and lose 1 point with probability 0.255.
  • Game 3: at each step, start with tossing a fair coin: head you play game 1, tail you play game 2.

If you simulate this (or write down the maths), you'll see that the expectation for the score after 1000 steps is negative for both game 1 and game 2; you will lose with both games. But mixing the two games randomly as in Game 3 produces a winning game!

Like datanalytics, I invite you to think about why that is.

Here is what the score distribution looks like for each game after 5000 iterations:

EDIT: Two probabilities were inverted (see comment by jkomi below). Text has been corrected now.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

4 Responses to Winning from losing

  1. jkomi says:

    >you win 1 point with probability 0.095 and lose 1 point with probability 0.905
    0.095 and 0.905 are reverse

    • CL says:

      Oops, you’re right; I inverted two probabilities but in the second case, not the first one.
      If current score=3k, you lose with probability 0.905.
      If current score=3k+1 or 3k+2, you lose with probability 0.255.
      It’s probably easier to read like this.
      I’m correcting the post. Thanks!

  2. Mitchus says:

    Nice counter-intuitive result :) Thanks, I enjoyed that a lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


3 × = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">