0% found this document useful (0 votes)
4 views2 pages

Card Simulation Experiment Analysis

The document describes generating a standard deck of 52 playing cards as a matrix. It then performs an experiment by randomly selecting and displaying 4 cards from the deck 10 times, printing TRUE if a face card is present and FALSE if not. Running the experiment 1000 times, it computes the number of TRUE and FALSE results, showing that the proportion converges to the actual probability of drawing a face card as the number of simulations increases.

Uploaded by

wefwefwe ewf ef
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Card Simulation Experiment Analysis

The document describes generating a standard deck of 52 playing cards as a matrix. It then performs an experiment by randomly selecting and displaying 4 cards from the deck 10 times, printing TRUE if a face card is present and FALSE if not. Running the experiment 1000 times, it computes the number of TRUE and FALSE results, showing that the proportion converges to the actual probability of drawing a face card as the number of simulations increases.

Uploaded by

wefwefwe ewf ef
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

#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.

You might also like