**r – psychonetrics**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This blog was written by Sacha Epskamp.

In my class on Structural Equation Modeling, I introduce the concepts of expected values and variances through the game of roulette. A french roulette game looks like this:

A ball will roll in the left basin and land on one of the 37 values. You can bet on a lot of different things, such as a single number, three numbers, a column, a row, even/odd, red/black, etcetera. All payouts are based such that the game is completely fair *if* the number zero was not included. Due to the number zero, however, the expected value of any bet is negative. For example, if we bet €10 on a single number, we expect to win:

```
> (36/37) * -10 + (1/37) * 350
[1] -0.2702703
```

That is, we expect to *lose* 27 cents. We can also look at the standard deviation:

```
> sqrt(1/37*(350 - -.27)^2 + (36/37) * (-10 - - 0.27)^2)
[1] 58.37838
```

If you do this for every possible bet, you will find that the expected value is almost always the same (a rare exception is the top line bet in American roulette, which is *even worse*), but the variance/standard deviation is different. This makes Roulette simply a game in which the player accepts a certain negative expected value, but chooses the variance that player wants to accept.

This negative expected value is why casinos make money: on average, players will lose more than they win. But to make money, casinos do need players to actually *play* the game. Why would anyone play a game that they are doomed to inevitably lose?

Given the negative expected value, you would expect to lose all your money pretty fast (say after 100 bets). Interestingly, that is not actually accurate. Suppose someone would go to the casino every week for a year (52 weeks), and bet 100 times 10 euro on the number 7 in French Roulette. We can simulate this in R:

```
set.seed(1)
profit <- replicate(52,{
sum(ifelse(sample(0:36,100,TRUE) == 7, 350, -10))
})
```

This better lost quite some money over the year:

```
> sum(profit)
[1] -5560
```

But half the times, this better ended the night with a profit for that night:

```
> mean(profit > 0)
[1] 0.5
```

This indicates that there is a fairly high chance to end up with a profit after a 100 bets even. How is that possible? Well, we know the expected value (EV) of one bet is -0.27 and the standard deviation (SD) is 58.38. From the rules of expectation and covariance algebra, we can derive that:

EV(n bets) = EV(bet1 + bet2 + ....) = EV(bet1) + EV(bet2) + EV(bet3) + ... = n * -0.27

Var(n bets) = Var(bet1 + bet2 + ...)

which due to independence follows to be:

= Var(bet1) + Var(bet2) + ... = n * Var(bet)

So the standard deviation becomes:

SD(n bets) = sqrt(n) * 58.38

This means that the expected value grows with a factor of *n*, but the standard deviation with a factor of the square root of *n*. Furthermore, because of the central limit theorem, such a sum of identically distributed random variables becomes approximately normal, and we can use the normal distribution to approximate probabilities. For example, we can approximate the probability that after 100 bets you still have a profit with:

```
> pnorm(0, 100 * -0.27, sqrt(100) * 58.39,lower.tail = FALSE)
[1] 0.4815592
```

Which is actually surprisingly high! Investigating the probability of having a profit after *n* bets leads to the following:

The solid line indicates the approximated probability using the normal distribution, and the error bars represent the 95% quantile region of the proportion of 52 occasions betting *n* times on 7 that ended in a profit (based on 100 simulations per level of *n*). Codes are available here. As you can see, even after 1,000 bets there is a decent probability (although of course less than 50%) of still having a profit.

What does that mean? Well, actually this is how casinos really make money. Offering games with a negative expected value is only half the story. If the variance is not high, people would simply immediately lose all their money, and would very quickly stop playing the game as a consequence. Instead, if people have a fairly high chance of stopping on a win, or if they only lose their money *very* slowly, they might keep playing, especially when this is coupled with some cognitive biases. Our gambler that betted 100 times every week for a year, for example, might not realize over the entire year 5,560 euro was lost (the gambler betted a total of 52,000 euro in the year combined), and might instead remember winning half the times. This may lead also to some false beliefs of being able to play the game well, as the player won so many times!

**leave a comment**for the author, please follow the link and comment on their blog:

**r – psychonetrics**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.