library(play4YES) set.seed(1234) # reproducible deck = build_deck() deck
table(suits(deck), faces(deck))
Make a biased deck:
bdeck = deck bdeck[3] = bdeck[18] table(suits(bdeck), faces(bdeck))
We'll use the built-in function sample
to
simulate shuffles of the deck. top_card
gives
the card at top of deck.
shuffle = sample top_card = function(x) x[1] t1 = top_card(shuffle(deck)) t1 suits(t1)
We'll take the top cards for each of 100 shuffles and examine the suit.
table( replicate(100, suits(top_card(shuffle(deck)))) )
We should see about 25 for each suit. Are we close enough?
table( replicate(100, suits(top_card(shuffle(bdeck)))) )
Variability can mask structural bias. If we create statistics based on more observations, we can start to unearth it.
table( replicate(10000, suits(top_card(shuffle(deck)))) ) table( replicate(10000, suits(top_card(shuffle(bdeck)))) )
There are 4 different suits, but 13 different faces. Is the bias discernible with this procedure?
table( replicate(100, faces(top_card(shuffle(deck)))) ) table( replicate(100, faces(top_card(shuffle(bdeck)))) )
If we make 10000 shuffles, we expect each face to appear 10000/13 = 769.230.... times.
tfair <- table( replicate(10000, faces(top_card(shuffle(deck)))) ) tfair tbias <- table( replicate(10000, faces(top_card(shuffle(bdeck)))) ) tbias
We can plot the observed frequencies of appearance of each face.
library(beeswarm) beeswarm(list(fair=tfair,biased=tbias), ylab="Top card face frequencies")
With the biased deck, one face has depleted frequency, one enhanced.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.