Assignment 2-probability

Author

Allison Shrivastava

  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. Hint: use expand.grid. rowSums, and length functions.
## create a grid of the possibilities
outcomes<-expand.grid(d1=1:6,d2=1:6,d3=1:6)
## now count up the number possibilities that the combination equals 12
length(which(rowSums(outcomes)==12))/nrow(outcomes)
[1] 0.12
##25/216=0.12
# probabilitiy of summing to 12 is 0.12
  1. 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 col.Sums to generate marginal probabilities.

#create a data frame
Residence<-c("Apartment","Dorm","With Parent(s)","Sorority/Fraternity House","Other")
Males<-c(200,200,100,200,200)
Females<-c(300,100,200,100,100)
gender_residence<-data.frame(Residence,Males,Females)
#count the total number of females 
sum(gender_residence$Females)
[1] 800
#800 females total, 100 in other
100/800
[1] 0.12
# 0.125 probability that a customer is female and lives in other
sum(gender_residence$Males)
[1] 900
#900 males total, 200 in other
200/900
[1] 0.22
# 0.222 probability that a customer is male and lives in other
  1. 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.
# first subtract 1 from 52 as a card has already been drawn
52-1
[1] 51
# then subtract 1 from 13 as there are 13 diamonds in a standard deck, and the first card was a diamond

13-1
[1] 12
# now calculate the probability of the remaining options
12/51
[1] 0.24
# 0.24 probability of a diamond
  1. 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.

    # 20 songs, selecting 10
    choose(20,10)
    [1] 184756
    #184756 lineups possible
  2. 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.

    #multiply number of tvs, sound systems and dvd players
    20*20*18
    [1] 7200
    #7200 potential combinations
  3. 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.

factorial(10)
[1] 3628800
  1. 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.

    # to keep everything straight, make vectors of the possible outcomes
     coin<-2^7
     dice<-6^3
     card<-choose(52,4)
    
     #now calculate the total potential outcomes
     coin*dice*card
    [1] 7485004800
     # 7485004800 potential outcomes
  2. 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.

    ## subtract 1 since the seats are alternating male/female
    factorial(4-1)*factorial(4)
    [1] 144
    # 144 possible seating arrangements
  3. 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 | +)? Show your R code. You may use a tree, table, or Bayes to answer this problem.

    #set outcomes as vectors to keep everything straight
    positive_user<-.95
    user<-.03
    negative_non_user<-.01
    non_user<-0.97
    ##probability positive and
    ## formula for bayesian probability is
    # P(A|B)=[P(B|A)*P(A)]/P(B)
    
    (positive_user*user)/((positive_user*user)+negative_non_user*non_user)
    [1] 0.75
  1. 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.

The probability that the other side is brown is 0.5 as there are only two possible outcomes, brown and golden. The pancake can either be Brown on side 1 & brown on side 2, or brown on side 1 & golden on side 2.

#possible outcomes for side 2
side_2_brown<-1
side_2_golden<-1

#posibity side 2 is brown/ all pancake possibilities
side_2_brown/(side_2_golden+side_2_brown)
[1] 0.5