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. Hint: use expand.grid. rowSums, and length functions.
Each roll can result in a value from 1 to 6, and by using expand grid we
can create a quick table of all potential totals after 3 rolls
##use expand.grid() to create a table with all possible 3-roll combos
grid<-expand.grid(roll1=1:6,roll2=1:6,roll3=1:6)
#sum up each combo
sums<-rowSums(grid)
#count how many sums are 12s
twelves<-length(which(sums==12))
#divide number of twelves by total combinations (6*6*6=216)
prob<-twelves/216
#Print result
prob
## [1] 0.1157407
This gives us a probability of 0.1157, or 11.57%
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.
Probability that a customer is male and lives in ‘Other’: 0.1176
Probability that a customer is male and lives in ‘Other’: 0.0588
Probability that a customer is male or female and lives in ‘Other’:
0.1765
Hint: create the matrix above in R, use rowSums and col.Sums to generate marginal probabilities.
#create matrix
males<-c(200,200,100,200,200)
females<-c(300,100,200,100,100)
customers<-matrix(c(males,females),nrow=5,byrow=FALSE)
customers
## [,1] [,2]
## [1,] 200 300
## [2,] 200 100
## [3,] 100 200
## [4,] 200 100
## [5,] 200 100
#Get total customers
totalcustomers<-sum(colSums(customers))
male_other<-customers[5,1]
female_other<-customers[5,2]
prob_m_other<-(male_other/totalcustomers)
prob_m_other
## [1] 0.1176471
prob_f_other<-(female_other/totalcustomers)
prob_f_other
## [1] 0.05882353
prob_other<-(male_other+female_other)/totalcustomers
prob_other
## [1] 0.1764706
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.
After the first draw, there will be 11 diamonds and 51 total cards left, resulting in a probability of 0.2157
## Number of cards left after first draw
cards_left<-52-1
##N Number of diamonds left
diamonds_left<-12-1
PDraw2_Diamond<-(diamonds_left/cards_left)
PDraw2_Diamond
## [1] 0.2156863
The next few questions are about permutation, combination, and
factorials.
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.
There are 184,756 possible lineups of 10 songs.
lineups<-choose(20,10)
lineups
## [1] 184756
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
You can create 7200 different combinations with these options.
#This will just be a simple multiplication of factors
#Create all factors
tvs<-20
surroundsounds<-20
dvds<-18
combos<-tvs*surroundsounds*dvds
combos
## [1] 7200
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
With each visit, the options for her next visit decrease by 1, making
this a factorial case.
10! = 3,628,800 different ways she can order her morning rounds.
#Calculatie 10!
diffways<-factorial(10)
diffways
## [1] 3628800
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 flip outcomes: 128
dice roll outcomes: 216
card draw outcomes: 270,725
Different outcomes possible: 7,485,004,800
#calculate coinflip outcomes
coinflip_outcomes<-2^7
coinflip_outcomes
## [1] 128
#calculate dice roll outcomes
dice_outcomes<-6^3
dice_outcomes
## [1] 216
#calculate card draw outcomes
draw_outcomes<-choose(52,4)
draw_outcomes
## [1] 270725
total_outcomes<- coinflip_outcomes*dice_outcomes*draw_outcomes
total_outcomes
## [1] 7485004800
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
Because it is a round table we can just start with one man and see the
permutations of the order of people to their right. 3!*4!=144
# 1 man is set, so 3 remain, along with the 4 women.
male_order<-factorial(3)
female_order<-factorial(4)
seating_order<- male_order*female_order
seating_order
## [1] 144
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(A|B)=( P(B|A) * P(A) ) / P(B)
P(User | +) = ( P(+ | User) * P(User)) / P(+)
P(+ | User)= 0.95
P(User)= 0.03
P(+)= P(+ | User)*P(User) + P(+ | Not User) * P(Not User)
= 0.95*0.03 + 0.01*0.97
= 0.0382
# Given probabilities
p_user <- 0.03
p_not_user <- 1 - p_user
p_pos_given_user <- 0.95
p_pos_given_not_user <- 1 - 0.99 # specificity is 99%
# Total probability of testing positive
p_pos <- p_pos_given_user * p_user + p_pos_given_not_user * p_not_user
# Bayes' Theorem: P(User | +)
p_user_given_pos <- (p_pos_given_user * p_user) / p_pos
# Print the result
p_user_given_pos
## [1] 0.7460733
Probability that a person who tests positive is actually a user: 0.7460733 = 0.7461
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.
Let’s call these 3 pancakes Brown-Brown, Brown-Gold, and Gold-Gold. We
withdraw one pancake and see a brown side. We know that means that we
are either holding Brown-Brown or Brown-Gold. There are 3 sides that we
could possibly be looking at and therefore 3 results for the remaining
side:
Brown-Brown Side 1 (Remaining side = Brown)
Brown-Brown Side 2 (Remaining side = Brown)
Brown-Gold Side 1 (Remaining side = Gold)
2 of the 3 possible scenarios would result in the other side being
brown. 2/3 = 0.6667
# Three pancakes: BB, GB, GG
total_brown<-3
#Possible favorable outcomes both come from BB
favorable<-2
prob_2ndBrown<-favorable/total_brown
prob_2ndBrown
## [1] 0.6666667