1 What is the probability of rolling a sum of 12 on three rolls of six-sided dice? Express your answer as a decimal number only. Show your R code.

outcome <- 12

combinations <- expand.grid(rep(list(1:6), 3))

possible.outcomes <- rowSums(combinations)

successful.outcome <- sum(possible.outcomes == outcome)

total.outcomes <- length(possible.outcomes)

probability <- successful.outcome/total.outcomes
probability
## [1] 0.1157407
round(probability, digits = 4)
## [1] 0.1157

It is important to note, when we set up the first line of our code using expand.grid, we did 1:6 since we are looking at the probabilities, not odds. This means it is the event: possible events. If we were looking at odds, we would do 1:5.

2. A newspaper company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of customers. The data is summarized in the table below. What is the probability that a customer is male and lives in ‘Other’ or is female and lives in ‘Other’? Express your answer as a decimal number only. Show your R code. Hint: create the matrix above in R, use rowSums and col.Sums to generate marginal probabilities.

newsData <- matrix(c(200,300,200,100,100,200,200,100,200,100),nrow=5, ncol=2, byrow = TRUE)

rownames(newsData) <- c("Apartment", 
                        "Dorm", 
                        "With Parent(s)", 
                        "Sorority/Fraternity House", 
                        "Other")

colnames(newsData) <- c("Males","Females")

pGender <- colSums(newsData, na.rm=FALSE,1) # Vector of Gender Probabilities

pGender
##   Males Females 
##     900     800
pResidence <- rowSums(newsData, na.rm=FALSE,1) # Vector of Residence Probabilities

pResidence
##                 Apartment                      Dorm            With Parent(s) 
##                       500                       300                       300 
## Sorority/Fraternity House                     Other 
##                       300                       300
totalCust <- sum(pResidence) # Total Number of Customers

p.male.female.other <- pResidence[5]/totalCust # customer is male and lives in 'Other' or is female and lives in 'Other'

p.male.female.other
##     Other 
## 0.1764706
round(p.male.female.other, digits = 4)
##  Other 
## 0.1765

We started this second problem by creating a matrix per the hint. We do not have an exact data set to work with so we had to create one. We start our code by creating a matrix to match the data we were provided in the newspaper table.In this matrix, we tell R to combine all the numbers of males and females in their respective residences. From there, we wanted to find the probability a customer was male or female and live in ‘other’. To do so we listed our code to be the probability of customers in residence 5 aka ’other”/total customers. We then round to four digits.

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? Express your answer as a decimal number only. Show your R code.

numberCards <- 52
diamonds <- 13
clubs <- 13
spades <- 13
hearts <- 13
  
pFirstDiamond <- diamonds/numberCards # the standard probability of selecting a diamond from the set, 13/52
pFirstDiamond
## [1] 0.25
pSecondDiamond <- (diamonds-1)/(numberCards-1) # probability of selecting a second diamond
pSecondDiamond
## [1] 0.2352941
round(pSecondDiamond, digits = 4)
## [1] 0.2353

The probability of drawing this second diamond after the previous diamond without replacement is 23.53%. Essentially, this just comes down to being 12/51 which gives us the same answer. It is important to note if we were to look at any other suit in the deck, it would be 13/51, but since we have one less diamond, we need to factor that into our final calculation.

4. A coordinator will select 10 songs from a list of 20 songs to compose an event’smusical entertainment lineup. How many different lineups are possible? Show your R code.

songCombos <- factorial(20) / (factorial(20-10)) # Permutation, No Repeats
songCombos
## [1] 670442572800

We use permutation without replacement for this and then used the code from the link from the HW where N = total songs and r = songs selected

5. You are ordering a new home theater system 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? Show your R code.

TVs <- 20
surround.sound <- 20
DVD.players <- 18

TVs*surround.sound*DVD.players
## [1] 7200

In order to find the total number of combinations, we just multiply each of these to get the total amount of different home theater systems which is 7,200.

6. A doctor visits her patients during morning rounds. In how many ways can the doctor visit 10 patients during the morning rounds? Show your R code.

factorial(10)
## [1] 3628800

There are 3,628,800 ways the doctor can visit patients in the morning rounds.

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 possible? Show your R code.

coin.sides <- 2
coin.tosses <- 7

dice.sides <- 6
dice.rolls <- 3

card.set <- 52
card.draws <- 4

# Coin Outcomes
coin.outcomes<- coin.sides^coin.tosses

# Dice Outcomes
dice.outcomes <- dice.sides^dice.rolls

Card.outcomes <- factorial(card.set)/(factorial(card.draws)*factorial(card.set-card.draws))

Total.Outcomes <- coin.outcomes*dice.outcomes*Card.outcomes
Total.Outcomes
## [1] 7485004800

There are a total of 7,485,004,800 different outcomes possible.

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 alternate seats. Show your R code.

men <- 4 
women <- 4 

seating.arrangements.men <- factorial(men - 1)
seating.arrangements.women <- factorial(women)

total.seating.arrangements <- (seating.arrangements.men * seating.arrangements.women)
total.seating.arrangements
## [1] 144

There are a total of 144 ways a party of four women and four men can be seated at a round table if they occupy alternate seats.

Bayesian Probability: 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 | +)? Show your R code. You may use a tree, table, or Bayes to answer this problem.

# Set up of equation
positive.user <- 0.95
negative.user <- 0.99
users <- 0.03

# Complements of each
positive.not.user <- (1-positive.user)
negative.not.user <- (1-negative.user)
not.users <- (1-users)


# Applying to Bayes Theorem

# P(User|+)= P(+|User)*P(User)/P(+|User)X P(user)+P(+|not user)*p(not user)

# Numerator in this problem
numerator <- positive.user*users

#Denominator in this problem
denominator <- (positive.user*users)+(negative.not.user)*(not.users)

P.PositveUser <- numerator/denominator
P.PositveUser
## [1] 0.7460733
round(P.PositveUser, digits = 4)
## [1] 0.7461

Per our calculations using Bayes Theorem, there is a 74.61% chance that a user who tests positive is actually a user.

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.

#probability of drawing each different type of pancake
golden.golden <- 1/3
brown.brown <- 1/3
golden.brown <- 1/3

#probability of drawing a brown side
P.golden.golden <- 0
P.brown.brown <- 1
P.golden.brown <- 1

probability.brown <- (golden.golden * P.golden.golden) + (brown.brown * P.brown.brown) + (golden.brown * P.golden.brown)
(probability.brown)
## [1] 0.6666667
round(probability.brown, digits = 4)
## [1] 0.6667

The probability that the other side is brown is 66.67%. Since we know one of the pancakes is golden on both sides, it essentially becomes 33% + 33%.