#11(c)
#(i)
# Generate a standard deck of 52 playing cards as a matrix:
faces = c("Jack", "Queen", "King")
value = c("Ace", 2:10, faces)
suit = c("Clubs", "Diamonds", "Hearts", "Spades")
deck = NULL
for (i in 1:4)
for (j in 1:13)
deck = rbind(deck, c(value[j], suit[i]))
deck = matrix(deck, nr=52, nc=2, dimnames = list(NULL, c("Value", "Suit")))
# To see the entire deck, type the word deck on a new
# command line, and hit Return. (Not required to submit.)
#________________________________________________________________
#(ii)
# Perform the experiment by manually running the code below
# N = 10 times. Each time, it randomly selects and displays
# four cards, prints "TRUE" if face card(s) present, else
# prints "FALSE":
cards = deck[sample(1:52, 4, replace = F), ]
cards
any(cards[, 1] %in% faces)
# Submit this output. Also, compute the proportion of TRUEs.
# How close is this statistic to the actual probability?
#_______________________________________________________________
#(iii)
# The code below runs N = 1000 simulations of this experiment,
# and computes and displays the number of TRUES and FALSES.
N = 1000 # You can make N bigger, if desired.
TRUES = 0
FALSES = 0
for (i in 1:N) {
cards = deck[sample(1:52, 4, replace = F), ]
if (any(cards[, 1] %in% faces) == T) TRUES = TRUES + 1 }
FALSES = N - TRUES
TRUES
FALSES
# How close is this proportion of TRUES for N = 1000 to the
# actual probability? How does this compare with N = 10?
# A sample-based estimator (such as proportion here) that
# converges (or more precisely, "converges in probability")
# to its intended population parameter as N becomes infinite,
# is said to be a "consistent" estimator of that parameter.