HW 6

Marbles

total <- 54+9+75 
p_red <- 54/total
p_white <- 9/total
p_blue <- 75/total
paste("The probabilty of picking a red or blue marble is",round(p_red+p_blue,4))
## [1] "The probabilty of picking a red or blue marble is 0.9348"

Mini Golf

golf_total <- 19+20+24+17
golf_green <- 19/golf_total
golf_red <- 20/golf_total
golf_blue <- 24/golf_total
golf_yellow <- 17/golf_total
paste("The probabilty of picking a red golf ball is",round(golf_red,4))
## [1] "The probabilty of picking a red golf ball is 0.25"

Pizza

pizza_total <- 81 + 116 + 215 + 130 + 129 + 228 + 79 + 252 + 97 + 72
paste("The probabilty that the customer is not male and lives with his parents is",round(1 - (215/pizza_total),4))
## [1] "The probabilty that the customer is not male and lives with his parents is 0.8463"

Independent or Dependent I

Going to the gym and losing weight are dependent events.

Wraps

veggies <- choose(8,3)#pick 3 of 8 veggies
condiments <- choose(7,3)#pick 3 of 7 condiments
tortilla <- choose(3,1)#pick 1 of 3 tortillas
total_wraps <- veggies*condiments*tortilla
paste("Total number of wraps to chose from is",total_wraps)
## [1] "Total number of wraps to chose from is 5880"

Independent or Dependent II

Jeff running out of gas on the way to work and Liz watching the evening news are independent events.

Presidential Cabinet

perm = function(n, x) {
  factorial(n) / factorial(n-x)
}
paste("The number of different ways the memeber of the cabinet can be appointed are", perm(14,8))
## [1] "The number of different ways the memeber of the cabinet can be appointed are 121080960"

Jellybeans

jelly_red <- choose(9,0) #get 0 of 9 red jellybeans
jelly_orange <- choose(4,1) #get 1 of 4 orange jellybeans
jelly_green <- choose(9,3) #get 3 of 9 orange jellybeans
jelly_total <- choose(22,4)#get 4 of 22 total jellybeans
jelly_prob <- (jelly_green*jelly_orange*jelly_red)/jelly_total
paste("The probability of getting 0 red, 1 orange, and 3 green jellybeans is",round(jelly_prob,4))
## [1] "The probability of getting 0 red, 1 orange, and 3 green jellybeans is 0.0459"

Factorial

paste('11!/7!=',factorial(11)/factorial(7))
## [1] "11!/7!= 7920"

Compliment

The compliment of 67% of subscribers being over the age of 34 is 33% of subscribers are 34 or younger.

Expected Value

heads <- pbinom(3, 4, 0.5) - pbinom(2, 4, 0.5)
paste("Probabilty of 3 heads is",heads)
## [1] "Probabilty of 3 heads is 0.25"
ev <- (97*heads) - (30*(1-heads)) #win - lose
paste("Expected value is",ev)
## [1] "Expected value is 1.75"
ev_win <- 559*ev
paste("If I play 559 times I can expect to win",ev_win)
## [1] "If I play 559 times I can expect to win 978.25"

Expected Value 2

tails <- pbinom(4, 9, 0.5)
paste("Probabilty of 4 tails or less is",tails)
## [1] "Probabilty of 4 tails or less is 0.5"
ev2 <- (23*tails) - (26*(1-tails)) #win - lose
paste("Expected value is",round(ev2,4))
## [1] "Expected value is -1.5"
ev2_win <- 994*ev2
paste("If I play 994 times I can expect to lose",abs(round(ev2_win,4)))
## [1] "If I play 994 times I can expect to lose 1491"

Polygraph

a)

p_liar <- .2
p_truth <- .8
p_sens<- .59
p_spec <- .9  

#probabilty of liar given that the polygraph detected  
#P(liar | positive test) / P(liar | positive test) + P(truth | positive test)
p_liar_sens <- (p_liar*p_sens) / ((p_liar*p_sens) + (p_truth*(1-p_spec)))
paste("The probabilty that an individual is a liar given that the polygraph detected is",round(p_liar_sens,4))
## [1] "The probabilty that an individual is a liar given that the polygraph detected is 0.596"

b)

#probabilty of truth teller given that the polygraph detected  
#P(truth | negative test) / P(truth | negative test) + P(liar | negative test)
p_liar_sens <- (p_truth*p_spec) / ((p_truth*p_spec) + (p_liar*(1-p_sens)))
paste("The probabilty that an individual is a truth-teller given that the polygraph detected is",round(p_liar_sens,4))
## [1] "The probabilty that an individual is a truth-teller given that the polygraph detected is 0.8978"

c)

#probability that someone was a liar or detected as one by the polygraph  
#P(liar) + P(truth | positive test )
paste("probability that someone was a liar or detected as one by the polygraph is",p_liar +((1 - p_spec)*p_truth))
## [1] "probability that someone was a liar or detected as one by the polygraph is 0.28"