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.
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.
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.
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
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.
factorial(10)
## [1] 3628800
There are 3,628,800 ways the doctor can visit patients in the morning rounds.
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.
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.
# 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.
#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%.