Q1

What is the probability of rolling a sum of 10 on a standard pair of six-sided dice? Express your answer as a decimal number only. Show your R code.

#Probability pulled from pg. 87 of the Openintor-stats: 3/36
prob10<-3/36
print(prob10)
## [1] 0.08333333

Q2

A newspaper company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of 1616 customers. The data is summarized in the table below.

Gender and Residence of Customers Residence Males Females Apartment 185 225 Dorm 284 83 With Parent(s) 122 218 Sorority/Fraternity House 187 56 Other 185 71

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<- 185
femaleother<-71
total<-1616
prob<-  (maleother/total) + (femaleother/total)
print(prob)
## [1] 0.1584158

Q3

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 heart? Express your answer as a decimal number only. Show your R code.

remaining<-52-1
probdia<-13/remaining
print(probdia)
## [1] 0.254902

Q4

A coin is tossed 4 times. How many different outcomes are possible? Show your R code.

2^4
## [1] 16

Q5

You are ordering a new home theater system that consists of a TV, surround sound system, and DVD player. You can choose from 16 different TVs, 22 types of surround sound systems, and 19 types of DVD players. How many different home theater systems can you build? Show your R code.

tv<-16
sss<-22
dvd<-19
theaterchoice<-tv*sss*dvd
print(theaterchoice)
## [1] 6688

Q6

A doctor visits her patients during morning rounds. In how many ways can the doctor visit 7 patients during the morning rounds? Show your R code.

a<-7:1
rounds<- numeric(length = length(a)) 
for (i in seq_along(a)) {
  rounds[i]<-a[i]
  
}
rounds
## [1] 7 6 5 4 3 2 1
prod(rounds)
## [1] 5040

Q7

A coordinator will select 8 songs from a list of 13 songs to compose an event’s musical entertainment lineup. How many different lineups are possible? Show your R code.

a<-13:6
songs<- numeric(length = length(a)) 
for (i in seq_along(a)) {
  songs[i]<-a[i]
  
}
songs
## [1] 13 12 11 10  9  8  7  6
prod(songs)
## [1] 51891840

Q8

A person rolls a standard six-sided die 6 times. In how many ways can he get 3 fives, 2 ones, and 1 three? Show your R code.

numerator<-factorial(6)
denominator<-factorial(3)*factorial(2)*factorial(1)
numerator/denominator
## [1] 60

Q9

You need to have a password with 6 letters followed by 2 odd digits between 0 and 9, inclusive. If the characters and digits cannot be used more than once, how many choices do you have for your password? Show your R code.

#factorial loop for letters
lttr<-26:21
pwl<- numeric(length = length(lttr)) 
for (i in seq_along(lttr)) {
  pwl[i]<-lttr[i]
  
}
lttr
## [1] 26 25 24 23 22 21
#factorial loop for digits
digits<-5:4
pwd<- numeric(length = length(digits)) 
for (i in seq_along(digits)) {
  pwd[i]<-digits[i]
  
}
digits
## [1] 5 4
prod(lttr)*prod(digits)
## [1] 3315312000

Q10

In how many ways can the letters in the word ‘Population’ be arranged? Show your R code.

lettercount<-nchar("Population")
factorial(lettercount)
## [1] 3628800
#Q11
choose(7,3)*choose(9,2)+
  choose(7,4)*choose(9,1)+
  choose(7,5)*choose(9,0)
## [1] 1596

Q11

A bag contains 7 green and 9 red jellybeans. How many ways can 5 jellybeans be withdrawn from the bag so that the number of red ones withdrawn will be less than 3? Show your R code.

choose(7,3)*choose(9,2)+
  choose(7,4)*choose(9,1)+
  choose(7,5)*choose(9,0)
## [1] 1596

Q12

A certain congressional committee consists of 14 senators and 9 representatives. How many ways can a subcommittee of 5 be formed if at least 2 of the members must be representatives? Show your R code.

sen<-14
rep<-9
choose(sen,3)*choose(rep,2)+
  choose(sen,2)*choose(rep,3)+
  choose(sen,1)*choose(rep,4)+
  choose(sen,0)*choose(rep,5)
## [1] 22638

Q13

If a coin is tossed 6 times, and then a standard six-sided die is rolled 2 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^6
dice<-6^2
card<-52*51*50*49
coinflip*dice*card
## [1] 14970009600

Q14

DJ Giovanni is making a playlist for a friend; he is trying to decide what 12 songs to play and in what order they should be played. If he has his choices narrowed down to 22 country, 11 reggae, and 5 pop songs, and he wants to play an equal number of country, reggae, and pop songs, how many different playlists are possible? Show your R code.

equalparts<-12/3

country<-22:(22-equalparts+1)
cfact<- numeric(length = length(country))
for (i in seq_along(country)) {
  cfact[i]<-country[i]
}
cchoice<-prod(cfact)


reggae<-11:(11-equalparts+1)
rfact<- numeric(length = length(country))
for (i in seq_along(reggae)) {
  rfact[i]<-reggae[i]
}
rchoice<-prod(rfact)

pop<-5:(5-equalparts+1)
pfact<- numeric(length = length(country))
for (i in seq_along(pop)) {
  pfact[i]<-pop[i]
}
pchoice<-prod(pfact)

cchoice*rchoice*pchoice
## [1] 166852224000

Q15

An English teacher needs to pick 13 books to put on her reading list for the next school year, and she needs to plan the order in which they should be read. She has narrowed down her choices to 5 novels, 7 plays, 7 poetry books, and 5 nonfiction books. If she wants to include no more than 2 nonfiction books, how many different reading schedules are possible? Show your R code.

novel<-5:0 plays<-7:0 pb<-7:0 nf<-2:0 tots<-13 novels<- c(5,4,3,2,1,0) plays<- c(7,6,5,4,3,2,1,0) poetrybooks<- c(7,6,5,4,3,2,1,0) nonfiction<- c(5,4,3,2,1,0)

I got stuck here. I can’t figure out how to get the loop to work so that “solution” works My goal was to then subtract all that don’t add upt to 13.

novchoose<-choose(5,l)

playchoose<-choose(7,k)

pbchoose<-choose(7,j)

nfchoose<-choose(5,i)

solution<-novchooseplaychoosepbchoose*nfchoose

for(l in 5:0) {

 for (k in 7:0) {

  for(j in 7:0) {

   for(i in 2:0){
   
      novchoose[l]<-choose(5,l)
   
      playchoose[k]<-choose(7,k)
   
      pbchoose[j]<-choose(7,j)
   
      nfchoose[i]<-choose(5,i)
   
      solution<-novchoose[l]*playchoose[k]*pbchoose[j]*nfchoose[i]
    
      }
    }
  } 
}

Q16

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 98% specific, meaning that if they did not use opioids within 30 days, they will test negative P( - | Not User) = .98. Assume that 4% 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.

#Probability of user
a1<-.04

#Probability of non-user
a2<-.96

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

# Probability (+|non-user)
bGivenNota<-.05

#Bayes Theorem
aGivenb<-(bGivena*a1)/((bGivena*a1)+(bGivenNota*a2))
print(aGivenb)
## [1] 0.4418605