#Probability- Show your Work in R

library(rmarkdown)
library(tinytex)
library(knitr)

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

two.dice <- function(){
  dice <- sample(1:6, size = 2, replace = TRUE)
  return(sum(dice))
}
two.dice()
## [1] 5
replicate(n = 3, expr = two.dice())
## [1] 9 8 8
dice.sum <- function(n.dice){
  dice <- sample(1:6, size = n.dice, replace = TRUE)
  return(sum(dice))
}
replicate(3, dice.sum(2))
## [1] 5 5 4
my.dice.sum <- function (n.side){
  dice <- sample(1:n.sides, size=n.dice, replace = TRUE)
  return(sum(dice))
}
s <- 6
n1 <-2
n <- 3
probability1 <- (1/s)^n1
probability <- (1/s)^n
print(probability1)
## [1] 0.02777778
print(probability)
## [1] 0.00462963

The probability of rolling a set of dice and getting a twelve is 0.0278. The probability of rolling three times six-sided dice and getting a twelve is 0.0046.

Question 2

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.

maleother <- 200
femaleother <- 100
total <- 1700
prob <- (maleother/total) + (femaleother/total)
print(prob)
## [1] 0.1764706

The probability that a customer is male and lives in “Other” or is female and lives in “Other” is 0.176

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

remaining <- 52-1
probdiamond <- 12/remaining
print(probdiamond)
## [1] 0.2352941

The probability of drawing a second diamond, after the first card drawn was a diamond, without replacement, is 0.235

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

int <- as.integer(readline(prompt = "Please enter a number"))
## Please enter a number
facto <- 1
facto <- factorial(int)
print(facto)
## [1] NA
ft1 <- factorial(20)
ft2 <- factorial(10)
print(ft1/ft2)
## [1] 670442572800

The amount of lineups that are possible are 6.704426e+12 or 670442572800.

Question 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
sss <- 20
dvd <- 18
theatersystems <- tv*sss*dvd
print(theatersystems)
## [1] 7200

There is a possibility to build up to 7200 different home theater systems.

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

d <- 10:1
rounds <- numeric(length = length(d))
for (i in seq_along(d)) {
  rounds[i]<-d[i]
}
rounds
##  [1] 10  9  8  7  6  5  4  3  2  1
prod(rounds)
## [1] 3628800

The amount of different ways that a doctor can visit 10 patients in the morning rounds would be 3628800.

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

coinflip <- 2^7
dice <- 6^3
card <- 52*51*50*49
coinflip*dice*card
## [1] 179640115200

There are 179640115200 different outcome that are possible from this situation.

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

int <- as.integer(readline(prompt = "Please enter a number"))
## Please enter a number
facto <- 1
facto <- factorial(int)  
print(facto)
## [1] NA
ftm <- factorial(3)
ftw <- factorial(4)
print(ftw *ftm)
## [1] 144

There are a total of 144 ways for the men and women to be arranged in the round table.

Question 9

An opiod urinalysis test is 95% sensitive for a 30-day period, meaning that if a person has actually used opiods 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 opiods 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 Byes to answer this problem.

 #Probaility of a User
au <- .03

#Probability of a Non-User
anu <- .97

#Probability (+|User)
bGivena <- .95

#Probability (+|Non User)
bGivenNota<- .05

#Bayes
aGivenb <- (bGivena*au)/((bGivena*au)+(bGivenNota*anu))
print(aGivenb)
## [1] 0.3701299

The probability of a person who tests positive being a user is 0.3701.

Question 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?

gg <- 1/3
gb <- 1/3
bb <- 1/3
probabilityofoneb <- 1/3 + 1/3
print(probabilityofoneb)
## [1] 0.6666667

The probability of having one side being brown is 0.67.