1) What is the Probability of rolling a sum of 12 on three rolls of six-sided dice?

# Using expand.grid to create a dataframe of all possible combinations from all 3 die
outcomes <- expand.grid(d1=1:6, d2=1:6, d3=1:6)
dim(outcomes)
## [1] 216   3

There are a total of 216 possible outcomes, now lets find out how many of those add to 12.

# Using rowSums and length functions to add up the sums of each row, and return the count of those that equal 12
outcomes12 <- length(which(rowSums(outcomes) == 12))
outcomes12
## [1] 25

Now we can dived the count of outcomes whose sum add is 12 (outcomes12), by the total number of outcomes (outcomes) to calculate the probability

outcomes12/nrow(outcomes)
## [1] 0.1157407

The probability of rolling a sum of 12 on three rolls of six-sided dice is 0.1157

2) A newspaper company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of costumers. The data is summarized in the table below

# creating a matrix that shows the Gender and Residence of Customers
table <- matrix(
    data = c(200, 300, 200, 100, 100, 200, 200, 100, 200, 100),
    nrow = 5,
    ncol = 2,
    byrow = TRUE
)
rownames(table) <- c("Apartmemt", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other")
colnames(table) <- c("Males", "Females")
table
##                           Males Females
## Apartmemt                   200     300
## Dorm                        200     100
## With Parent(s)              100     200
## Sorority/Fraternity House   200     100
## Other                       200     100

What is the probability that a customer is male and lives in ‘Other’ or is a female and lives in ‘Other’?

First we will add the marginal probabilities to our matrix

# To find the total count
total_count <- sum(table)

# Probability of each row and column
row_prob <- rowSums(table) / total_count
col_prob <- colSums(table) / total_count

#add these to our data matrix
table_prob <- cbind(table, row_prob)
table_prob <- rbind(table_prob, c(col_prob, sum(row_prob)))
table_prob
##                                 Males     Females  row_prob
## Apartmemt                 200.0000000 300.0000000 0.2941176
## Dorm                      200.0000000 100.0000000 0.1764706
## With Parent(s)            100.0000000 200.0000000 0.1764706
## Sorority/Fraternity House 200.0000000 100.0000000 0.1764706
## Other                     200.0000000 100.0000000 0.1764706
##                             0.5294118   0.4705882 1.0000000

From the matrix we created above, we see there is 0.1765 chance that a customer is a male or female and lives in ‘Other’

3)Two cards are drawn without replacement from a standard deck of 52 playing cards. What is the probability of choosing a diamond for the second card drawn, if the first card, drawn without replacement, was a diamond?

#Creating a deck of 52 cards
card_deck <- 52

# Diving the deck by 4 to get the count of card that are diamonds
diamond_cards <- card_deck / 4

# removing the first card drawn that was a diamond
new_card_deck <- card_deck - 1
new_diamond_cards <- diamond_cards - 1

# Calculating the probability of choosing a diamond card as the second card drawn
diamond_card_prob <- new_diamond_cards / new_card_deck
diamond_card_prob
## [1] 0.2352941

There is a 0.2353 chance that a diamond card is drawn as the second card, if the first card, drawn without replacement, was a diamond

4) A coordinator will selct 10 songs from a list of 20 songs to compose an event’s musical entertainment lineup. How many different lineups are possible?

We will use the permutations formula with out repeats n! / (n-r)!

# Setting our variables
n <- 20
r <- 10

# Plugging them into our equation n! / (n-r)!
possible_lineups <- factorial(n) / factorial(n-r)
possible_lineups
## [1] 670442572800

There are 670,442,572,800 possible lineups.

5) You are ordering a new home theater that consists of a TV, surround sound system, and DVD player. You can choose from 20 different TVs, 20 types of surround sound systems, and 18 types of DVD players. How many different home theater systems can you build?

We will use the multiplication rule of Counting for this

tv <- 20 #20 tvs
sss <- 20 #20 surround sound systems
dvdp <- 18 #18 dvd players

diff_theaters <- tv * sss * dvdp
diff_theaters
## [1] 7200

There are 7200 different home theater systems you can build.

6) A doctor visits her patients during morning rounds. In how many ways can the doctor visit 10 patients during the morning rounds

We will use the Factorial rule of counting for this

factorial(10)
## [1] 3628800

There are 3628800 different ways the doctor could visit the 10 patients.

7) If a coin is tossed 7 times, and then a standard six-sided die is rolled 3 times, and finally a group of four cards are drawn from a standard deck of 52 cards without replacement, how many different outcomes are there?

coin_toss <- 2^7 # 2 sides, 7 tosses
dice_roll <- 6^3 # 6 sides, 3 tosses
card_draw <- factorial(52) / (factorial(4) * factorial(52-4)) # choosing 4 cards from 52 without replacement

total_outcomes <- coin_toss * dice_roll * card_draw
card_draw
## [1] 270725
total_outcomes
## [1] 7485004800

There are 7,485,004,800 possible outcomes.

8) In how many ways may a party of four women and four men be seated at a round table if the women and men are to occupy alernate seats?

# Assigning variables
men <- 4
women <- 4

# Calculate possible outcomes
seating_combo <- factorial(men - 1)* factorial(women)
seating_combo
## [1] 144

There are 144 possible seating arrangements

Bayesian probability

9) An opioid urinalysis test is 95% sensitive for a 30-day period, meaning that if a person has actually used opioids within 30 days, they will test positive 95% of the time P( + | User) =.95. The same test is 99% specific, meaning that if they did not use opioids within 30 days, they will test negative P( - | Not User) = .99. Assume that 3% of the population are users. Then what is the probability that a person who tests positive is actually a user P(User | +)?

We will use Bayes` Theorem to solve this.

# B = positive, A1 = User, A2 = not a user
# g should be read as given, ex. BgA1 should be read as B given A1
BgA1 <- 0.95 # Someone will test positive 95% of the time given they are a user
A1 <- 0.03 # 3% of the population are users
BgA2 <- 1 - 0.99 # someone will test negative 99% of the time if they are not a user
A2 <- 0.97 # population who are not users

# plug into Bayes` Theorem
A1gB <- (BgA1 * A1)/((BgA1 * A1) + (BgA2 * A2))
A1gB
## [1] 0.7460733

The probability is 0.7461

10) You have a hat in which there are three pancakes. One is golden on both sides, one is brown on both sides, and one is golden on one side and brown on the other. You withdraw one pancake and see that one side is brown. What is the probability that the other side is brown? Explain.

This is similar to the Monty Hall Probability Problem, so we will solve it as such

# with 3 pancakes in the hat to start, each pancake has 1/3 chance in being picked
gg <- 1/3 #golden both side
bg <- 1/3 #golden one side, brown one side
bb <- 1/3 #brown both sides
# We pull a pancake and now we know one side is brown, we can remove gg
probability_brown <- bg + bb
probability_brown
## [1] 0.6666667

There is a probability of .6667 the other side will be brown.