Practice: Intro Probability

1) Deck of Cards

Consider a standard deck of 52 cards, as displayed in the following figure.

Consider the following events when a card is randomly selected.

  • \(A\): card selected is a heart.

  • \(B\): card selected is color black.

  • \(C\): card selected is a face card (i.e. J, Q, K)

  • \(D\): card selected is a King.

Find the following probabilities.

  1. \(P(A)\)

  2. \(P(B)\)

  3. \(P(C)\)

  4. \(P(D)\)

  5. \(P(A^c)\)

  6. \(P(B^c)\)

  7. \(P(C^c)\)

  8. \(P(D^c)\)

  9. \(P(A \cap B)\)

  10. \(P(A \cup B)\)

  1. 13/52 = 1/4
  2. 26/52 = 1/2
  3. 12/52
  4. 4/52 = 1/13
  5. 1 - (13/52) = 3/4
  6. 1 - (26/52) = 1/2
  7. 1 - (12/52) = 40/52
  8. 1 - (4/52) = 48/52
  9. 0 because A and B are mutually exclusive
  10. P(A) + P(B) = 13/52 + 26/52 = 39/52

R code refresher

sample(): takes an input vector x, and draws a random sample of a certain size with or without replacement (replace)

vec = 1:10

# sample without replacement
sample(vec, size = 3) 

# sample with replacement
sample(vec, size = 3, replace = TRUE)


set.seed(): a number (integer) used by the random number generator(s) in R. It allows us to reproduce the output of sample() and other functions that generate random numbers in R.

set.seed(4321)

# reproducible sample
sample(letters, size = 5)

2) Flipping a coing

  1. Create a character vector coin that simulates the 2 sides of a coin "heads" and "tails"

  2. Use sample() to simulate tossing a coin 6 times

Show answer
coin <- c("heads", "tails")

sample(coin, size = 6, replace = TRUE)

3) Rolling a die

  1. Create a numeric vector die that simulates the sides of a die (1, 2, 3, 4, 5, 6)

  2. Use sample() to simulate tossing a die 10 times

Show answer
die <- 1:6

sample(die, size = 10, replace = TRUE)

4) Rolling a pair of dice

  1. With your die vector—from the preceding question—write code to simulate rolling a pair of dice, and getting the sum of the spots.
Show answer
die <- 1:6

sum(sample(die, size = 2, replace = TRUE))

5) GO BEARS

  1. Create a character vector box containing the letters in the phrase GO BEARS.

  2. Write R code to sample all the letters from box without replacement. Repeat this process no more than 100 times.

  3. If you get a sample "G" "O" "B" "E" "A" "R" "S" (in this order) you win.

Show answer
box <- c("G", "O", "B", "E", "A", "R", "S")

# run the following command 100 times
sample(box, size = 7)