How the House Makes a Profit: A R Shiny App for Explaining the Key Idea to Gambling

[This article was first published on R – Curtis Miller's Personal Website, 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.

As many of you may know, I teach statistics at the University of Utah. Below is a post about how industries based on chance events, such as casinos or insurance companies, are able to guarantee a profit. I have also included R code for a Shiny app that demonstrates the ideas discussed in the blog post.

Several industries’ core business model is based on being on the opposite side of “bets” on chance events made by their customers. The gambling industry, such as casinos and lotteries, is the most notable example of such an industry, but so is the insurance industry and financial sevices and investment companies, especially when selling derivatives like stock options. (George R. R. Martin, in his novel A Dance with Dragons, made the interesting observation that the difference between gambling and insurance is that when you gamble, you place a bet you hope to win, while with insurance you place a bet you hope to lose).

Let’s focus on the gambling industry. This includes casinos and lotteries, but let’s simply call the party on the other side of a bet “the house”. When the house offers a game, that game needs to:

  • Encourage as many gamblers as possible to play the game
  • Make as large a profit as possible

These are two competing objectives that are not easily balanced. To see this, recognize first that you would eagerly pay $1 to play a game where you win $1,000,001 if a coin flip lands heads-up, but the house would quickly go bankrupt. On the other hand, you would never pay $1,000,000 to play a game that pays $1,000,001 (a $1 profit) when a coin lands heads-up, even though this is an extremely profitable game for the house any time someone plays. Somehow the house needs to design a game that falls between these two extremes.

First, realize that the house views the games they offer differently than gamblers. While the gambler may play for a few hours, perhaps even one-hundred games, the amount he plays a game is miniscule compared to the times the house plays. Because the house is on the opposite side of every bet made, they play their games far more than any gambler possibly could. This implies that the Law of Large Numbers strongly impacts the total profits of the house, and the house can expect average profits to equal the theoretical profit of the game. It’s highly unlikely that a game with a negative profitability for the gambler (which equates to positive profitability for the house) to actually result in a loss for the house, so every game the house offers should be games that offer the house an advantage, even if that advantage is small.

Every game the house offers should be a losing game for the gambler, but the objective of the house is to hide this fact. In order for the house to induce gamblers to play, the house needs to design a game where the Law of Large Numbers works slowly; a gambler would need to play many games in order to see the true (negative) profitability of the game (and by then, it may be too late for the poor gambler). The house does this by making the standard deviation of the game’s winnings very large. This could be done by making the game’s pay-in small and the gambler having a seemingly good chance of winning any game, yet not be receiving enough in the pay-out to compensate for the gambler’s losses; this may appeal to the cautious gambler who wants to play many games (perhaps this is the idea behind roulette). Another alternative is to have a small pay-in, a small chance of winning, and a seemingly huge pay-out (like the lottery) that, while large, again doesn’t compensate for average losses; this game may appeal to the one-off gambler looking for some occasional excitement. Either game may have a large standard deviation (to see this in the latter case, remember that the standard deviation is very sensitive to outliers) yet still have a negative expected value, and so the house can expect to make a profit while the gambler, confused by the game’s large standard deviation, is induced to play.

Suppose a gambler finds himself addicted, and plays many games. While the gambler may see more wins, the Law of Large Numbers will kick in and make the gambler’s average winnings look like the theoretical profitability of the game, which is negative for the gambler (positive for the house). This is why gambling a lot is worse than gambling once (or, in the case of the lottery, buying lots of lotto tickets to win, like this idiot suggests), and the gambler is best off playing a game as few times as possible, if at all.GamblerShinyApp

Congratulations! You just got a job with the Little Monaco Hotel and Casino in Las Vegas as a statistician! Your first job is to design a simple game where the gambler has some probability (specified by you) of winning. Code for the applet is below. In the first tab of the app, pick the probability of winning, the pay-in, and the gambler’s profit if she wins. You can view simulated runs of your game with average payoffs in the first screen; feel free to change how many simulations and trials per simulation are computed. Can you design a game with a negative expected profit (which is good for your employer) that also requires a large number for the trials for the Law of Large Numbers to effect the average profit? What’s a good combination of pay-in, profit on win, and probability of winning?

You can change some parameters associated with this applet (such as starting bank roll) in the Options tab.

library(ggplot2)
library(shiny)
 
shinyApp(
    ui = fluidPage(tabsetPanel(
        tabPanel("Design", sidebarLayout(sidebarPanel(
                     numericInput("payin", "Pay-In", 1, min = 0.01, step = .01),
                     numericInput("profit", "Profit", .95, min = 0.01, step = 0.01),
                     numericInput("prob", "Probability of Win", 0.5, min = 0, max = 1, step = 0.01)),
                 mainPanel(
                     textOutput("profit_text"),
                     textOutput("sd_text"),
                     plotOutput("simplot")
                ))),
#        tabPanel("Play", actionButton("play", "Play"),
#                 actionButton("reset", "Reset")),
        tabPanel("Options",
#                 numericInput("budget", "Starting Budget", 10000, min = 0.01),
                 numericInput("runs", "Number of Trials to Simulate", 5000, min = 1),
                 numericInput("sims", "Number of Simulations", 30, min = 1))
    )),
    server = function(input, output) {
        output$simplot <- renderPlot({
            simdat <- sapply(1:input$sims, function(rid) {
                res <- rbinom(input$runs, size = 1, prob = input$prob)
                winnings <- ifelse(res == 1, input$profit, -input$payin)
                return(sapply(1:input$runs, function(v) mean(winnings[1:v])))
            })
            simdat_data <- data.frame(run = paste("run", rep(1:input$sims, each = input$runs), sep = "_"), trial = rep(1:input$runs, times = input$sims), profit = as.vector(simdat))
            ggplot(simdat_data) +
                geom_line(aes(x = trial, y = profit, group = run), alpha = 0.1, size = 2) +
                geom_hline(yintercept = input$prob * input$profit - (1-input$prob)*input$payin, color = "red") +
                ggtitle("Simulated Profit Distribution")
        })
        output$profit_text <- renderText({
            paste("Expected Profit (for Gambler):", round(input$prob * input$profit - (1-input$prob)*input$payin, digits = 2))
        })
        output$sd_text <- renderText({
            paste("Winnings Standard Deviation:", round(sqrt((input$profit+input$payin)*(input$prob*(1-input$prob))), digits = 2))
        })
    }
)


To leave a comment for the author, please follow the link and comment on their blog: R – Curtis Miller's Personal Website.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)