Alternative Decks in mmcards

This vignette explores three alternative types of decks offered by the ‘mmcards’ package that may better suit your specific use case compared to a standard 52-card deck. First, load the ‘mmcards’ library, and then we’ll play simple games to illustrate how each deck works.

library(mmcards)

AnonymousDeck

Suppose you’re teaching a statistical concept and want to simulate drawing samples from a population. In that case, you can define a custom AnonymousDeck and play a game to drive the idea home.

Whose Card is Closer to the Population Mean?

# Define the Players
p1 <- NULL
p2 <- NULL

# Create a shuffled anonymous deck of 10 cards using a random number seed for reproducibility
game_deck <- shuffle_deck(deck_of_cards = function(x){rnorm(10, 0, 5)},
seed = 147)

# Deal a card to each player
game_deck <- deal_card(game_deck)
p1 <- game_deck$dealt_card game_deck <- deal_card(game_deck) p2 <- game_deck$dealt_card

# Display the cards and determine the winner
paste("p1 has:", p1$card, "with a value of", p1$value)
#> [1] "p1 has: 8 with a value of 2.21542965936812"
paste("p2 has:", p2$card, "with a value of", p2$value)
#> [1] "p2 has: 1 with a value of -9.39463929631786"
paste0("The winner is: ", ifelse(abs(p1$value) < abs(p2$value), "p1", "p2"))
#> [1] "The winner is: p1"

# Here are the remaining 8 cards in the deck
print(game_deck$updated_deck) #> card value #> 5 5 -2.519066 #> 3 3 -2.771481 #> 4 4 -2.678679 #> 6 6 -1.461480 #> 2 2 -3.768717 #> 9 9 4.658202 #> 10 10 8.255931 #> 7 7 1.201079 InterleavedDeck If you want to simulate drawing samples from two distinct populations, an InterleavedDeck can be useful. Whose Card is Closer to the Population Mean? with Biased Decks # Define the Players p1 <- NULL p2 <- NULL # Create a shuffled interleaved deck of 10 cards using a random number seed for reproducibility game_deck <- shuffle_deck(deck_of_cards = function(x){list(rnorm(5, 0, 5), rnorm(5, 0, 3))}, seed = 157) # Deal a card to each player game_deck <- deal_card(game_deck) p1 <- game_deck$dealt_card

game_deck <- deal_card(game_deck)
p2 <- game_deck$dealt_card # Display the cards and determine the winner paste("p1 has:", p1$card, "with a value of", p1$value) #> [1] "p1 has: A_3 with a value of 2.5268783375614" paste("p2 has:", p2$card, "with a value of", p2$value) #> [1] "p2 has: B_2 with a value of -1.45153422895941" paste0("The winner is: ", ifelse(abs(p1$value) < abs(p2$value), "p1", "p2")) #> [1] "The winner is: p2" # Here are the remaining 8 cards in the deck print(game_deck$updated_deck)
#>    card       value
#> 2   A_2  2.58087475
#> 41  B_4  3.56098941
#> 4   A_4  9.75742338
#> 51  B_5  2.71402888
#> 1   A_1  0.06059832
#> 31  B_3 -3.18706595
#> 5   A_5  8.46972493
#> 11  B_1 -0.79511543

PairedDeck

A PairedDeck is ideal for games that require maintaining a natural pairing between cards, such as in a paired t-test scenario.

Hanging from Pull-up Bar: Left Hand vs Right Hand

# Define the hands
LH <- NULL
RH <- NULL

# Create a shuffled paired deck of 20 cards using a random number seed for reproducibility
game_deck <- shuffle_deck(deck_of_cards = function(x){list(rpois(10, 30),
rnorm(10, 40))},
seed = 232,
paired = TRUE)

# For the student whose cards came out on top, get the hang time for each hand
game_deck <- deal_card(game_deck)
LH <- game_deck$dealt_card game_deck <- deal_card(game_deck) RH <- game_deck$dealt_card

# Display the cards and determine which hand was stronger
paste("This student's left hand card is:",
LH$card, "with a value of", LH$value)
#> [1] "This student's left hand card is: A_6 with a value of 32"
paste("This student's right hand card is:", RH$card, "with a value of", RH$value)
#> [1] "This student's right hand card is: B_6 with a value of 40.8653697233691"
paste0("Did this student hang for longer with left hand?: ",
ifelse(LH$value > RH$value, "Yes", "No"))
#> [1] "Did this student hang for longer with left hand?: No"

# Here are the remaining students' hang times
print(game_deck\$updated_deck)
#>     card    value
#> 2    A_2 23.00000
#> 21   B_2 41.56952
#> 9    A_9 30.00000
#> 91   B_9 39.67030
#> 5    A_5 32.00000
#> 51   B_5 39.52775
#> 7    A_7 23.00000
#> 71   B_7 40.55928
#> 4    A_4 21.00000
#> 41   B_4 41.16555
#> 3    A_3 36.00000
#> 31   B_3 41.39362
#> 10  A_10 31.00000
#> 101 B_10 37.64896
#> 8    A_8 21.00000
#> 81   B_8 40.62200
#> 1    A_1 39.00000
#> 11   B_1 40.82121

Notice that the students’ order is shuffled but the LH and RH pairs are intact.