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.
diceCombos <- expand.grid(d1 = 1:6, d2 = 1:6, d3 = 1:6) # all combinations of rolling 3 dice
allSums <- rowSums(diceCombos) # Sum of each row in a vector, same length as # of combos
sumTo12 <- which(allSums==12) # creates vector from allSums the equal 12
pOf12 = length(sumTo12)/length(diceCombos) # P(3 dice summing to 12) = length of sumTo12 divided by length of all combinations
pOf12
## [1] 8.333333
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 colSums 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
pMorFinOther <- pResidence[5]/totalCust # customer is male and lives in 'Other' or is female and lives in 'Other'
pMorFinOther
## Other
## 0.1764706
numberCards <- 52
pFirstDiamond <- 1 / (numberCards/4) # 1 out of All Diamonds (52/4)
pSecondDiamond <- 1 / ((numberCards-1)/4) # One Less Diamond
pSecondDiamond
## [1] 0.07843137
X—XX— X—XX—X—XX—X—XX— X—XX <!- The next few questions are about permutation, combination, and factorials. Permutation relates to the act of arranging all the members of a set into some sequence or order. EG. Arranging people, digits, numbers, alphabets, letters, and colours are examples of permutations. However, combination is a way of selecting items from a collection, such that (unlike permutations) the order of selection does not matter. EG. Selection of menu, food, clothes, subjects, the team are examples of combinations. Basic History and Comparison Chart Formulas summary (no repeats is the more common usage)- Also, the factorial function (symbol: !) just means to multiply a series of descending natural numbers. Examples: • 4! = 4 × 3 × 2 × 1 = 24 • 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040 • 1! = 1 Note: it is generally agreed that 0! = 1. It may seem funny that multiplying no numbers together gets us 1, but it helps simplify a lot of equations. How to implement them in R - https://davetang.org/muse/2013/09/09/combinations-and-permutations-in-r/ –>
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. install.packages(‘gtools’) library(gtools)
songCombos <- factorial(20) / (factorial(20-10)) # Permutation, No Repeats
songCombos
## [1] 670442572800
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.
theaterCombos <- 20*20*18
theaterCombos
## [1] 7200
drVisits <- factorial(10) # Combination, No Repeats
drVisits
## [1] 3628800
nTosses <- 7
nRolls <- 3
nDraws <- 4
coinSet <- 2
diceSet <- 6
cardSet <- 52
coinOutcomes <- coinSet^nTosses # Combination, Repeats
diceOutcomes <- diceSet^nRolls # Combination, Repeats
cardOutcomes <- factorial(cardSet) / (factorial(nDraws) * (factorial(cardSet-nDraws))) # Combinations, No Repeats
totalOutcomes <- coinOutcomes * diceOutcomes * cardOutcomes
totalOutcomes
## [1] 7485004800
permOfMW <- factorial(4) / (factorial(4 - 2)) # Get How many permutations of MW of 4 pick 2
# I don't think we need this one, as the MW on a round table will satisfy the problem
permOfWM <- factorial(4) / (factorial(4 - 2)) # Get How many permutations of WM of 4 pick 2
seatCombo <- factorial(1 + 4 -1) / factorial(1) * factorial(4 - 1) # Get How many Combos of 4 sets of MW
#totalSeatCombos <- permOfMW * permOfWM * seatCombo # multiply results
totalSeatCombos <- permOfMW * seatCombo
totalSeatCombos
## [1] 1728
P(other side brown) = 1/2 = 0.5
Explanation: two pancakes have a brown side, you pulled out one of them, so you have a 50% chance the other side is brown