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.

sides <- 6
total_sum <- 12

all_probs <- expand.grid(rep(list(1:sides),3))

probability <- function(total_sum){
  sum <- rowSums(all_probs)
  num_true <- sum(sum  == total_sum)
  total_combinations <- length(sum)
  func_prob <- num_true/total_combinations
  return(func_prob)
}

probability(total_sum)
## [1] 0.1157407

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.

 ##Create data matrix 5x2
GRC_data <- c(200, 200, 100, 200, 200, 300, 100, 200, 100, 100)
Gender_Residence_Customers <- matrix(GRC_data, nrow = 5, ncol = 2)

Gender <- c("Male", "Female")
Residence <- c("Apartment", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other")

rownames(Gender_Residence_Customers) <- Residence
colnames(Gender_Residence_Customers) <- Gender

Row_Total <- rowSums(Gender_Residence_Customers)
Col_Total <- colSums(Gender_Residence_Customers)

GRC <- cbind(Gender_Residence_Customers, Row_Total)
GRC
##                           Male Female Row_Total
## Apartment                  200    300       500
## Dorm                       200    100       300
## With Parent(s)             100    200       300
## Sorority/Fraternity House  200    100       300
## Other                      200    100       300
Total_Customers <- sum(Row_Total)

Male_Other <- Gender_Residence_Customers[5,1]
Female_Other <- Gender_Residence_Customers[5,2]
Other <- sum(Male_Other, Female_Other)

Total_Other <- sum(Male_Other, Female_Other)

Probability_Other <- function(Gender_Residence_Customers){
  Other <- Male_Other/Total_Customers + Female_Other/Total_Customers
  return(Other)
}

Probability_Other(Gender_Residence_Customers)
## [1] 0.1764706
##Verify the Function
300/1700
## [1] 0.1764706

Therefore, the probability that a customer is a male that lives in other or a female that lives in other is 17.65% or 0.1765.

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.

library(prob)
## Loading required package: combinat
## 
## Attaching package: 'combinat'
## The following object is masked from 'package:utils':
## 
##     combn
## Loading required package: fAsianOptions
## Loading required package: timeDate
## Loading required package: timeSeries
## 
## Attaching package: 'timeSeries'
## The following objects are masked from 'package:graphics':
## 
##     lines, points
## Loading required package: fBasics
## Loading required package: fOptions
## 
## Attaching package: 'prob'
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, union
##Set variable Prob_Cards to cards function
Prob_Cards <- cards(jokers = FALSE,makespace = TRUE)

##Create subset of cards to show probability of Diamond suit
Prob_Diamond <- subset(Prob_Cards, suit == "Diamond")
Prob_Diamond
##    rank    suit      probs
## 14    2 Diamond 0.01923077
## 15    3 Diamond 0.01923077
## 16    4 Diamond 0.01923077
## 17    5 Diamond 0.01923077
## 18    6 Diamond 0.01923077
## 19    7 Diamond 0.01923077
## 20    8 Diamond 0.01923077
## 21    9 Diamond 0.01923077
## 22   10 Diamond 0.01923077
## 23    J Diamond 0.01923077
## 24    Q Diamond 0.01923077
## 25    K Diamond 0.01923077
## 26    A Diamond 0.01923077
##Set variable A to urnsample function to draw 2 cards without replacement
A <- urnsamples(Prob_Cards, size = 2)

##Set variable B to define probability space as a list with 2 values outcomes and probabilities
B <- probspace(A)

summary(B)
##          Length Class  Mode   
## outcomes 1326   -none- list   
## probs    1326   -none- numeric
##Calculate probability if both cards are diamonds
Prob(B, all(suit == "Diamond"))
## [1] 0.05882353
##Verify answer by multiplying probabilities of both card pulls
(13/52)*(12/51)
## [1] 0.05882353

Source: https://www.wyzant.com/resources/answers/714231/remaining-2-two-cards-are-drawn-without-replacement-from-a-standard-deck-of

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

To accurately solve this question the permutation formula should be used because the order matters in regard to song lineup.

\(P_{n,x}\) is a variable that represents the number of different combinations of x objects from a set of n elements, given by the following formula:

\(_{n}P_{x} = \frac{n!}{(n-x)!}\)

Continuing

\(_{20}P_{10} = \frac{20!}{10!}\)

\(_{20}P_{10} = 670442572800\)

Therefore in R it would be represented:

n <- 20
x <- 10
permutation_func <- function(n,x){
  return(factorial(n)/factorial(n-x))
}

permutation_func(20, 10)
## [1] 670442572800

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.

TV <- 20
SS <- 20
DVD <- 18

num_HTSys <- TV * SS * DVD
num_HTSys
## [1] 7200

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.

patients <- 10
Combinations <- factorial(patients)

print(Combinations)
## [1] 3628800

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.

This problem was solved using standard permutation with replacement for flipping a coin and die rolls while drawing 4 cards was represented as a permutation without replacement. Therefore, using \(n^{r}\) for both the dice roll and the coin flips, and the permutation function used earlier where \(_{n}P_{x} = \frac{n!}{(n-x)!}\), each outcome was multiplied to find the final amount of different outcomes of 179640115200. Please see below

coin_flips <- 7
die_rolls <- 3

coin_outcomes <- 2
die_outcomes <- 6
card_outcomes <- permutation_func(52,4)

Total_Outcomes <- (coin_outcomes^coin_flips)*(die_outcomes^die_rolls)*card_outcomes

print(Total_Outcomes)
## [1] 179640115200

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
people <- men + women

arrangements <- function(men,women){
  return(factorial(men-1)*factorial(women))
}

arrangements(men, women)
## [1] 144

First the amount of men are placed around the table in alternate order represented by (men - 1)!. Then the women are placed around the table represented by women!. Therefore the number of outcomes is represented by multiplying these two values to be 144 number of possible arrangements.

9. 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 | +)?

P_pos_user <- 0.95
P_neg_nonuser <- 0.99
P_user <- .03

##Set inverse probabilities
P_nonuser <- (1 - P_user)
P_pos_nonuser <- (1 - P_neg_nonuser)
P_neg_user <- (1 - P_pos_user)

Using Bayes Formula

\(P(A \mid B) = \frac{P(A)*P(B \mid A)}{P(B)}\)

substituting the values it can be represented as

\(P(User \mid +) = \frac{P(+ \mid User)*P(User)}{P(+ \mid User)*P(User)+P(+ \mid NonUser)*P(NonUser)}\)

bayestheorem <- function(P_pos_user,P_user,P_pos_nonuser,P_nonuser){
  P_user_pos <- (P_pos_user*P_user)/((P_pos_user*P_user)+(P_pos_nonuser*P_nonuser))
  return(P_user_pos)
}

bayestheorem(P_pos_user,P_user,P_pos_nonuser,P_nonuser)
## [1] 0.7460733

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.

Using Bayes Theorem we can assign variables x and y to represent golden and brown respectively. Therefore:
\(P(y) = (P(no sides)*P(y \mid no sides)) + (P(one side)*P(y \mid one side)) + (P(both sides)*P(y \mid both sides))\)

y <- 1/2
P_nosides <- 0
P_oneside <- 1
P_bothsides <- 1

P_y_nosides <- 1/3
P_y_oneside <- 1/3
P_y_bothsides <- 1/3

P_y <- (P_nosides*P_y_nosides)+(P_oneside*P_y_oneside)+(P_bothsides*P_y_bothsides)

P_y
## [1] 0.6666667

Understanding conditional probabilities and Bayes theorem, the probability that a given a side of a pancake is brown is 1/2 or 3/6. One pancake has no brown sides represented by a probability of 1/3. Whereas a pancake with a at least one brown side is represented by a probability of 2/3. Because the pancake selected showed one side was brown, in other words selected and not replaced, there are three sides that could be golden or brown. Because we know that there is only one side that is golden out of the two pancakes that have brown sides the probability that the other side of the selected pancake is golden is 1/3 and the probability that the other side of the selected pancake is brown is 2/3.