Ayala Cohen’s homework for Data Science Math Week 2

  1. There are 540 identical plastic chips numbered 1 through 540 in a box. What is the probability of reaching into the box and randomly drawing the chip numbered 505? Express your answer as a fraction or a decimal number rounded to four decimal places.
p <- 1/540
round(p, digits = 4)
## [1] 0.0019
  1. Write out the sample space for the given experiment. Separate your answers using commas. When deciding what you want to put into a salad for dinner at a restaurant, you will choose one of the following extra toppings: asparagus, cheese. Also, you will add one of following meats: eggs, turkey. Lastly, you will decide on one of the following dressings: French, vinaigrette. (Note: Use the following letters to indicate each choice: A for asparagus, C for cheese, E for eggs, T for turkey, F for French, and V for vinaigrette.)
extratoppings <- c("A", "C")
meats <- c("E", "T")
dressings <- c("F", "V")

salad <- c(sample(extratoppings,1),sample(meats,1),sample(dressings,1))
salad
## [1] "C" "E" "V"

Please note: I spent a very long time trying to figure out how to use a loop or a function to write out the full sample space in R, without having to manually write out a lot of letters in a vector, but I couldn’t quite get it, so I’m submitting the full answer below. Sample space = {AEF, ATF, AEV, ATV, CEF, CTF, CEV, CTV}

  1. A card is drawn from a standard deck of 52 playing cards. What is the probability that the card will be a heart and not a face card? Write your answer as a fraction or a decimal number rounded to four decimal places.
prob <- (13-3)/52
round(prob, digits = 4)
## [1] 0.1923
  1. A standard pair of six-sided dice is rolled. What is the probability of rolling a sum less than 6? Write your answer as a fraction or a decimal number rounded to four decimal places.
probsumdicelessthan6 <- 10/36
round(probsumdicelessthan6, digits = 4)
## [1] 0.2778
  1. A pizza delivery company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of 2001 customers. The data is summarized in the table below.

Gender and Residence of Customers Males Females Apartment 233 208 Dorm 159 138 With Parent(s) 102 280 Sorority/Fraternity House 220 265 Other 250 146

What is the probability that a customer is male? Write your answer as a fraction or a decimal number rounded to four decimal places.

probmale <- ((233+159+102+220+250)/2001)
round(probmale, digits = 4)
## [1] 0.4818
  1. Three cards are drawn with replacement from a standard deck. What is the probability that the first card will be a club, the second card will be a black card, and the third card will be a face card? Write your answer as a fraction or a decimal number rounded to four decimal places.
card1club <- 13/52
card2black <- 26/52
card3face <- 12/52
prob3card <- card1club * card2black * card3face
round(prob3card,digits = 4)
## [1] 0.0288
  1. Two cards are drawn without replacement from a standard deck of 52 playing cards. What is the probability of choosing a spade for the second card drawn, if the first card, drawn without replacement, was a heart? Write your answer as a fraction or a decimal number rounded to four decimal places.
card1heart <- 13/52
card2spade51 <- 13/51
prob2card <- card1heart * card2spade51
round(prob2card, digits = 4)
## [1] 0.0637
  1. Two cards are drawn without replacement from a standard deck of 52 playing cards. What is the probability of choosing a heart and then, without replacement, a red card? Write your answer as a fraction or a decimal number rounded to four decimal places.
prob1heart <- 13/52
prob2red <- 25/51
prob2cards <- prob1heart * prob2red
round(prob2cards, digits = 4)
## [1] 0.1225
  1. There are 85 students in a basic math class. The instructor must choose two students at random.

Students in a Basic Math Class Males Females Freshmen 12 12 Sophomores 19 15 Juniors 12 4 Seniors 7 4

What is the probability that a junior female and then a freshmen male are chosen at random? Write your answer as a fraction or a decimal number rounded to four decimal places.

probjrfemale <- 4/85
probfreshmale <- 12/84
prob2students <- probjrfemale * probfreshmale
round(prob2students, digits = 4)
## [1] 0.0067
  1. Out of 300 applicants for a job, 141 are male and 52 are male and have a graduate degree.

Step 1. What is the probability that a randomly chosen applicant has a graduate degree, given that they are male? Enter your answer as a fraction or a decimal rounded to four decimal places.

probmale <- 141/300
probmalegrad <- 52/300
probgradgivenmale <- probmalegrad/probmale
round(probgradgivenmale, digits = 4)
## [1] 0.3688

Step 2. If 102 of the applicants have graduate degrees, what is the probability that a randomly chosen applicant is male, given that the applicant has a graduate degree? Enter your answer as a fraction or a decimal rounded to four decimal places.

probgrad <- 102/300
probmalegivengrad <- probmalegrad/probgrad
round(probmalegivengrad, digits = 4)
## [1] 0.5098
  1. A value meal package at Ron's Subs consists of a drink, a sandwich, and a bag of chips.  There are 6 types of drinks to choose from, 5 types of sandwiches, and 3 types of chips.  How many different value meal packages are possible?
drink <- c(1:6)
sandwich <- c(1:5)
bagchips <- c(1:3)
valuemeal <- (length(drink) * length(sandwich) * length(bagchips) )
valuemeal
## [1] 90
  1. A doctor visits her patients during morning rounds.  In how many ways can the doctor visit 5 patients during the morning rounds?
patientvisit <- 5*4*3*2*1
patientvisit
## [1] 120
  1. A coordinator will select 5 songs from a list of 8 songs to compose an event's musical entertainment lineup.  How many different lineups are possible?
musiclineup <- 8*7*6*5*4
musiclineup
## [1] 6720
  1. A person rolls a standard six-sided die 9 times.  In how many ways can he get 3 fours, 5 sixes and 1 two?
roll9 <- ((9*8*7*6)/(3*2))
roll9
## [1] 504
  1. How many ways can Rudy choose 6 pizza toppings from a menu of 14 toppings if each topping can only be chosen once?
pizza6toppings14 <- (14*13*12*11*10*9)/(6*5*4*3*2)
pizza6toppings14
## [1] 3003
  1. 3 cards are drawn from a standard deck of 52 playing cards.  How many different 3-card hands are possible if the drawing is done without replacement?
hand3cards <- (52*51*50) / (3*2)
hand3cards
## [1] 22100
  1. You are ordering a new home theater system that consists of a TV, surround sound system, and DVD player.  You can choose from 12 different TVs, 9 types of surround sound systems, and 5 types of DVD players.  How many different home theater systems can you build?
tv <- c(1:12)
soundsys <- c(1:9)
dvd <- c(1:5)
hometheater <- (length(tv) * length(soundsys) * length(dvd) )
hometheater
## [1] 540
  1. You need to have a password with 5 letters followed by 3 odd digits between 0 - 9 inclusively.  If the characters and digits cannot be used more than once, how many choices do you have for your password?
pw5letters3odddigits <- 26*25*24*23*22*5*4*3
pw5letters3odddigits
## [1] 473616000
  1. Evaluate the following expression.
    _9 P_4
perm9comma4 <- 9*8*7*6
perm9comma4
## [1] 3024
  1. Evaluate the following expression.
    _11 C_8
comb11comma8 <- (11*10*9)/(3*2)
comb11comma8
## [1] 165
  1. Evaluate the following expression.
    ( _12 P_8)/( _12 C_4 )
permdivcomb <- (12*11*10*9*8*7*6*5)/ ((12*11*10*9)/(4*3*2))
permdivcomb
## [1] 40320
  1. The newly elected president needs to decide the remaining 7 spots available in the cabinet he/she is appointing.  If there are 13 eligible candidates for these positions (where rank matters), how many different ways can the members of the cabinet be appointed?
cabinetappoint <- 13*12*11*10*9*8*7
cabinetappoint
## [1] 8648640
  1. In how many ways can the letters in the word 'Population' be arranged?
arrangepopulation <- ( (10*9*8*7*6*5*4*3*2) / ( (2) * (2) ) )
arrangepopulation
## [1] 907200
  1. Consider the following data:

x 5 6 7 8 9 p(x) 0.1 0.2 0.3 0.2 0.2

Step 1. Find the expected value E( X ). Round your answer to one decimal place.

x <- c(5, 6, 7, 8, 9)
px <- c(0.1, 0.2, 0.3, 0.2, 0.2)
expval <- sum(x * px)
round(expval,digits = 1)
## [1] 7.2

Step 2. Find the variance. Round your answer to one decimal place.

var <- sum( (x-expval)^2 * px)
round(var,digits = 1)
## [1] 1.6

Step 3. Find the standard deviation. Round your answer to one decimal place.

sd <- sqrt(var)
round(sd,digits = 1)
## [1] 1.2

Step 4. Find the value of P(X ³ 9). Round your answer to one decimal place.

probxgreaterorequal9 <- 0.2
probxgreaterorequal9
## [1] 0.2

Step 5. Find the value of P(X £ 7). Round your answer to one decimal place.

probxlessthanorequal7 <- sum(0.1, 0.2, 0.3)
probxlessthanorequal7
## [1] 0.6
  1. Suppose a basketball player has made 188 out of 376 free throws.  If the player makes the next 3 free throws, I will pay you $23.  Otherwise you pay me $4.

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

oddsofmakingfreethrow <- 188/376
oddsofnotmakingfreethrow <- 1-(188/376)
oddsofmaking3freethrows <- oddsofmakingfreethrow * oddsofmakingfreethrow * oddsofmakingfreethrow
oddsofnotmaking3freethrows <- oddsofnotmakingfreethrow * oddsofnotmakingfreethrow * oddsofnotmakingfreethrow
expectedvalue <- (oddsofmaking3freethrows * 23) - (oddsofnotmaking3freethrows * 4)
round(expectedvalue, digits = 2)
## [1] 2.38

Step 2. If you played this game 994 times how much would you expect to win or lose? (Losses must be entered as negative.)

expectedvalue994 <- (expectedvalue * 994)
expectedvalue994
## [1] 2360.75
  1. Flip a coin 11 times.  If you get 8 tails or less, I will pay you $1.  Otherwise you pay me $7.

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

numsuccess <- 8
numtrials <- 11
probsuccess <- 0.5

prob8tails <- (factorial(numtrials)/ (factorial(numsuccess)*factorial(numtrials-numsuccess)) ) * probsuccess^numsuccess * (1-probsuccess)^(numtrials-numsuccess)

prob7tails <- (factorial(numtrials)/ (factorial(7)*factorial(numtrials-7)) ) * probsuccess^7 * (1-probsuccess)^(numtrials-7)

prob7tails <- (factorial(numtrials)/ (factorial(7)*factorial(numtrials-7)) ) * probsuccess^7 * (1-probsuccess)^(numtrials-7)

prob6tails <- (factorial(numtrials)/ (factorial(6)*factorial(numtrials-6)) ) * probsuccess^6 * (1-probsuccess)^(numtrials-6)
prob5tails <- (factorial(numtrials)/ (factorial(5)*factorial(numtrials-5)) ) * probsuccess^5 * (1-probsuccess)^(numtrials-5)
prob4tails <- (factorial(numtrials)/ (factorial(4)*factorial(numtrials-4)) ) * probsuccess^4 * (1-probsuccess)^(numtrials-4)
prob3tails <- (factorial(numtrials)/ (factorial(3)*factorial(numtrials-3)) ) * probsuccess^3 * (1-probsuccess)^(numtrials-3)
prob2tails <- (factorial(numtrials)/ (factorial(2)*factorial(numtrials-2)) ) * probsuccess^2 * (1-probsuccess)^(numtrials-2)
prob6tails <- (factorial(numtrials)/ (factorial(6)*factorial(numtrials-6)) ) * probsuccess^6 * (1-probsuccess)^(numtrials-6)
prob1tails <- (factorial(numtrials)/ (factorial(1)*factorial(numtrials-1)) ) * probsuccess^1 * (1-probsuccess)^(numtrials-1)
prob0tails <- (factorial(numtrials)/ (factorial(0)*factorial(numtrials-0)) ) * probsuccess^0 * (1-probsuccess)^(numtrials-0)

prob8orlesstails <- prob8tails + prob7tails + prob6tails + prob5tails + prob4tails + prob3tails + prob2tails + prob1tails + prob0tails

expvalprop <- (prob8orlesstails * 1) - ( (1-prob8orlesstails)*7)
round(expvalprop,digits = 2)
## [1] 0.74

Step 2. If you played this game 615 times how much would you expect to win or lose? (Losses must be entered as negative.)

expgamewin <- expvalprop * 615
expgamewin
## [1] 454.043
  1. If you draw two clubs on two consecutive draws from a standard deck of cards you win $583.  Otherwise you pay me $35.  (Cards drawn without replacement.)

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

prob1club <- 13/52
prob2club <- 12/51
probbothclubs <- prob1club * prob2club
evcardgame <- (probbothclubs * 583) - ((1-probbothclubs) * 35)
round(evcardgame,digits = 2)
## [1] 1.35

Step 2. If you played this game 632 times how much would you expect to win or lose? (Losses must be entered as negative.)

expwincards <- evcardgame * 632
expwincards
## [1] 855.0588
  1. A quality control inspector has drawn a sample of 10 light bulbs from a recent production lot.  If the number of defective bulbs is 2 or less, the lot passes inspection.  Suppose 30% of the bulbs in the lot are defective.  What is the probability that the lot will pass inspection? (Round your answer to 3 decimal places)
numdefective <- 2
numbertrials <- 10
probdefective <- 0.3

prob2defective <- (factorial(numbertrials)/ (factorial(numdefective)*factorial(numbertrials-numdefective)) ) * probdefective^numdefective * (1-probdefective)^(numbertrials-numdefective)

prob1defective <- (factorial(numbertrials)/ (factorial(1)*factorial(numbertrials-1)) ) * probdefective^1 * (1-probdefective)^(numbertrials-1)

prob0defective <- (factorial(numbertrials)/ (factorial(0)*factorial(numbertrials-0)) ) * probdefective^0 * (1-probdefective)^(numbertrials-0)

probpassinspect <- prob2defective + prob1defective + prob0defective
round(probpassinspect,digits = 3)
## [1] 0.383
  1. A quality control inspector has drawn a sample of 5 light bulbs from a recent production lot.  Suppose that 30%  of the bulbs in the lot are defective.  What is the expected value of the number of defective bulbs in the sample?  Do not round your answer. 
nsample <- 5
probdefbulb <- 0.3
evdefect <- nsample * probdefbulb
evdefect
## [1] 1.5
  1. The auto parts department of an automotive dealership sends out a mean of 5.5 special orders daily. What is the probability that, for any day, the number of special orders sent out will be more than 5? (Round your answer to 4 decimal places)
meanspecorderdaily <- 5.5

prob5specialorders <- (meanspecorderdaily^5 * exp(-meanspecorderdaily) ) / factorial(5)

prob4specialorders <- (meanspecorderdaily^4 * exp(-meanspecorderdaily) ) / factorial(4)

prob3specialorders <- (meanspecorderdaily^3 * exp(-meanspecorderdaily) ) / factorial(3)

prob2specialorders <- (meanspecorderdaily^2 * exp(-meanspecorderdaily) ) / factorial(2)

prob1specialorders <- (meanspecorderdaily^1 * exp(-meanspecorderdaily) ) / factorial(1)

prob0specialorders <- (meanspecorderdaily^0 * exp(-meanspecorderdaily) ) / factorial(0)

probmorethan5specorders <- 1 - (prob5specialorders + prob4specialorders + prob3specialorders + prob2specialorders + prob1specialorders + prob0specialorders)
round(probmorethan5specorders, digits = 4)
## [1] 0.4711
  1. At the Fidelity Credit Union, a mean of  5.7 customers arrive hourly at the drive-through window.  What is the probability that, in any hour, more than 4 customers will arrive? (Round your answer to 4 decimal places)
meancustomersperhour <- 5.7

prob4custinanhour <- (meancustomersperhour^4 * exp(-meancustomersperhour) ) / factorial(4)

prob3custinanhour <- (meancustomersperhour^3 * exp(-meancustomersperhour) ) / factorial(3)

prob2custinanhour <- (meancustomersperhour^2 * exp(-meancustomersperhour) ) / factorial(2)

prob1custinanhour <- (meancustomersperhour^1 * exp(-meancustomersperhour) ) / factorial(1)

prob0custinanhour <- (meancustomersperhour^0 * exp(-meancustomersperhour) ) / factorial(0)

probmorethan4custhour <- 1 - (prob4custinanhour + prob3custinanhour + prob2custinanhour + prob1custinanhour + prob0custinanhour) 
round(probmorethan4custhour, digits = 4)
## [1] 0.6728
  1. The computer that controls a bank's automatic teller machine crashes a mean of  0.4 times per day. What is the probability that, in any 7-day week, the computer will crash no more than 1 time? (Round your answer to 4 decimal places)
meancrashesperday <- 0.4
meancrashesperweek <- 0.4 * 7

prob1crashinweek <- (meancrashesperweek^1 * exp(-meancrashesperweek) ) / factorial(1)

prob0crashinweek <- (meancrashesperweek^0 * exp(-meancrashesperweek) ) / factorial(0)

probnomorethan1crash <- prob1crashinweek + prob0crashinweek
round(probnomorethan1crash, digits = 4)
## [1] 0.2311
  1. A town recently dismissed 8 employees in order to meet their new budget reductions.  The town had 6 employees over 50 years of age and 19 under 50.  If the dismissed employees were selected at random, what is the probability that more than 1 employee was over 50?  Write your answer as a fraction or a decimal number rounded to three decimal places.
numover50 <- 2
numberdismissed <- 8
probover50 <- 6/25

prob2over50 <- (factorial(numberdismissed)/ (factorial(numover50)*factorial(numberdismissed-numover50)) ) * probover50^numover50 * (1-probover50)^(numberdismissed-numover50)

prob3over50 <- (factorial(numberdismissed)/ (factorial(3)*factorial(numberdismissed-3)) ) * probover50^3 * (1-probover50)^(numberdismissed-3)

prob4over50 <- (factorial(numberdismissed)/ (factorial(4)*factorial(numberdismissed-4)) ) * probover50^4 * (1-probover50)^(numberdismissed-4)

prob5over50 <- (factorial(numberdismissed)/ (factorial(5)*factorial(numberdismissed-5)) ) * probover50^5 * (1-probover50)^(numberdismissed-5)

prob6over50 <- (factorial(numberdismissed)/ (factorial(6)*factorial(numberdismissed-6)) ) * probover50^6 * (1-probover50)^(numberdismissed-6)

prob7over50 <- (factorial(numberdismissed)/ (factorial(7)*factorial(numberdismissed-7)) ) * probover50^7 * (1-probover50)^(numberdismissed-7)

prob8over50 <- (factorial(numberdismissed)/ (factorial(8)*factorial(numberdismissed-8)) ) * probover50^8 * (1-probover50)^(numberdismissed-8)

probmorethan1over50 <- prob2over50 + prob3over50 + prob4over50 + prob5over50 + prob6over50 + prob7over50 + prob8over50
round(probmorethan1over50,digits = 3)
## [1] 0.608
  1. Unknown to a medical researcher, 10 out of  25 patients have a heart problem that will result in death if they receive the test drug.  Eight patients are randomly selected to receive the drug and the rest receive a placebo.  What is the probability that less than 7 patients will die?  Write your answer as a fraction or a decimal number rounded to three decimal places.
probheartproblem <- 10/25
numpatientdrug <- 8
numwilldie <-6

prob6willdie <- (factorial(numpatientdrug)/ (factorial(numwilldie)*factorial(numpatientdrug-numwilldie)) ) * probheartproblem^numwilldie * (1-probheartproblem)^(numpatientdrug-numwilldie)

prob5willdie <- (factorial(numpatientdrug)/ (factorial(5)*factorial(numpatientdrug-5)) ) * probheartproblem^5 * (1-probheartproblem)^(numpatientdrug-5)

prob4willdie <- (factorial(numpatientdrug)/ (factorial(4)*factorial(numpatientdrug-4)) ) * probheartproblem^4 * (1-probheartproblem)^(numpatientdrug-4)

prob3willdie <- (factorial(numpatientdrug)/ (factorial(3)*factorial(numpatientdrug-3)) ) * probheartproblem^3 * (1-probheartproblem)^(numpatientdrug-3)

prob2willdie <- (factorial(numpatientdrug)/ (factorial(2)*factorial(numpatientdrug-2)) ) * probheartproblem^2 * (1-probheartproblem)^(numpatientdrug-2)

prob1willdie <- (factorial(numpatientdrug)/ (factorial(1)*factorial(numpatientdrug-1)) ) * probheartproblem^1 * (1-probheartproblem)^(numpatientdrug-1)

prob0willdie <- (factorial(numpatientdrug)/ (factorial(0)*factorial(numpatientdrug-0)) ) * probheartproblem^0 * (1-probheartproblem)^(numpatientdrug-0)

problessthan7willdie <- prob6willdie + prob5willdie + prob4willdie + prob3willdie + prob2willdie + prob1willdie + prob0willdie
round(problessthan7willdie, digits = 3)
## [1] 0.991