** DATA_605_Assignment_6_Thonn - Probability **
# install libraries if needed
#install.packages("permutations")
#library(permutations)
#install.packages('gtools')
#library(gtools)
** Problem-1 **
# marble counts
red <- 54
white <- 9
blue <- 75
total1 <- red + white + blue
total1
## [1] 138
# [1] 138
# probability or red or blue
prob_red_blue <- (red + blue) / total1
round(prob_red_blue,4)
## [1] 0.9348
# [1] 0.9348
** Problem-2 **
# ball count
green <- 19
red <- 20
blue <- 24
yellow <- 17
total2 <- green + red + blue + yellow
round(total2,2)
## [1] 80
# [1] 80
# probaiblity of a red golf ball
probability_red <- red / total2
round(probability_red,4)
## [1] 0.25
# [1] 0.25
** Problem-3 **
Gender and Residence of Customers Males Females Apartment 81 228 Dorm 116 79 With Parent(s) 215 252 Sorority/Fraternity House 130 97 Other 129 72
What is the probability that a customer is not male or does not live with parents? Write your answer as a fraction or a decimal number rounded to four decimal places.
Note: The probability of union of two events is given by: \(P(A \cup B) = P(A) + P(B) - P(A \cap B)\)
# total amount
total3 <- 81 + 228 + 116 + 79 + 215 + 252 + 130 + 97 + 129 + 72
total3
## [1] 1399
#[1] 1399
# probability a customer is not male
probability_not_male <- (228 + 79 + 252 + 97 + 72) / total3
round(probability_not_male,4)
## [1] 0.5204
#[1] 0.5204
# probability customer does not live with parents
probability_not_live_parents <- (81 + 228 + 116 + 79 + 130 + 97 + 129 + 72) / total3
round(probability_not_live_parents,4)
## [1] 0.6662
# [1] 0.6662
# intersection between not_male and not_parents
prob_not_male_and_not_parents <- (228 + 79 + 97 + 72)/ total3
round(prob_not_male_and_not_parents,4)
## [1] 0.3402
# [1] 0.3402
# overall problem 3 solution
prob3_overall <- probability_not_male + probability_not_live_parents - prob_not_male_and_not_parents
round(prob3_overall,4)
## [1] 0.8463
# [1] 0.8463
** Problem-4 **
Determine if the following events are independent. Going to the gym. Losing weight. 4. Select Answer: A) Dependent B) Independent
Answer-4: These events dependent as going to the gym can influence losing weight.
** Problem-5 **
Answer-5:
# There are 3 different vegetables and 3 different condiments and 1 tortilla. find the number of combinations
vegetables <- choose(8, 3)
vegetables
## [1] 56
# [1] 56
condiments <- choose(7, 3)
condiments
## [1] 35
# [1] 35
tortillas <- choose(3, 1)
tortillas
## [1] 3
# [1] 3
# Number of different vegie wraps that can be made:
number_veg_wraps <- vegetables * condiments * tortillas
number_veg_wraps
## [1] 5880
# [1] 5880
** Problem-6 **
Select Answer: A) Dependent B) Independent
Answer-6: These events are Independent as one event does not influence the other.
** Problem-7 **
factorial(14)
## [1] 87178291200
factorial(14 - 8)
## [1] 720
# As rank matters permutation will be used
ways_candidates_appointed <- factorial(14)/(factorial(14 - 8))
ways_candidates_appointed
## [1] 121080960
# [1] 121,080,960
** Problem-8 **
#Note: withdrawing jellybeans are independent events.
red <- 9
orange <- 4
green <- 9
total1 <- red + orange + green
# number different combinations for drawing random 4 jellybeans from bag
jellybean_4draw <- choose(total1, 4)
# ways to obtain 0 reds, 1 orange and 3 greens
red_combination <- choose(red, 0)
orange_combination <- choose(orange, 1)
green_combinbation <- choose(green, 3)
# overall probability
pr_jellybean <- (red_combination * orange_combination * green_combinbation) / jellybean_4draw
round(pr_jellybean,4)
## [1] 0.0459
# [1] 0.0459
** Problem-9 **
11! = 11 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 7! = 7 * 6 * 5 * 4 * 3 * 2 * 1
answer_9 <- factorial(11)/factorial(7)
answer_9
## [1] 7920
# [1] 7920
** Problem-10 **
Answer-10: Complement: 33% of subscribers to a fitness magazine are 34 years of age or younger.
** Problem-11 **
# probability four tosses.
total_toss <- 2^4
head_zero <- choose(4, 0)/total_toss
head_one <- choose(4,1)/total_toss
head_two <- choose(4,2)/total_toss
head_three <- choose(4, 3)/total_toss
head_four <- choose(4, 4)/total_toss
prob_head <- c(head_zero, head_one, head_two, head_three, head_four)
num_head <- 0:4
head_df1 <- data.frame(num_head, prob_head)
# expected value
# if exactly 3 heads = win $97, otherwise lose $30
win_loss <- c(-30,-30,-30,97, -30)
expected_value <- sum(win_loss * head_df1[,2])
expected_value
## [1] 1.75
# Answer-11-1: [1] 1.75
# win $1.75
Step 2. If you played this game 559 times how much would you expect to win or lose? (Losses must be entered as negative.)
expected_win_559 <- 559 * 1.75
expected_win_559
## [1] 978.25
# [1] 978.25
** Problem-12 **
Step 1. Find the expected value of the proposition. Round your answer to two decimal places.
# probability of win 4 tails or less
pr_win_4_tails_or_less <-pbinom(4,size=9, prob=0.5)
pr_win_4_tails_or_less
## [1] 0.5
# [1] 0.5
expected_value_4_9 <-round(23*pr_win_4_tails_or_less - 26*(1-pr_win_4_tails_or_less))
expected_value_4_9
## [1] -2
# [1] -2
Step 2. If you played this game 994 times how much would you expect to win or lose? (Losses must be entered as negative.)
# for 994 plays
expected_outcome_994 <- 994 * expected_value_4_9
expected_outcome_994
## [1] -1988
# [1] -1988
** Problem-13 **
truth_teller_est (tte): .8 tte_detect_truth: .8 * .9 tte_detect_lie: .8 * (1 - .9)
lie_est (le): .2 le_detect_truth: .2 * (1-.59) le_detect_lie: .2 * .59
# probability of actually a liar|detected as a liar
# P(A|B) = (P(B|A)P(A))/P(B)
#prob detected as a liar: P(B)= (0.8*0.1) + (0.2*0.59 )
#prob actually a liar: P(A)=0.2
#prob given actually a liar versus detected as a liar: P(B|A)= 0.2*0.59
pr_a_giv_b_1 <-(0.2*0.59)*0.2/(0.8*0.1+0.2*0.59)
round(pr_a_giv_b_1,4)
## [1] 0.1192
#Answer-13-a: [1] 0.1192
# Probability actually truth-teller|detected as a truth-teller
# P(A|B) = (P(B|A)P(A))/P(B)
#prob detected as a truth-teller: P(B)= 0.8*0.9+0.2*(1-0.59)
#probability actually a truth-teller: P(A)=0.8
#probability given actually a truth-teller versus detected as a truth-teller: P(B|A)= 0.8*0.9
pr_a_giv_b_2 <-(0.8*0.9)*0.8/(0.8*0.9+0.2*(1-0.59))
round(pr_a_giv_b_2,4)
## [1] 0.7182
# Answer-13-b: [1] 0.7182
# Probability of actually a truth-teller|detected as a truth-teller)
#prob truth teller detected as a liar: P(B)= 0.8*(1-0.9)
#prob liar detected as a liar: P(A)=0.2*0.59
p_a_plus_b <- (0.8*(1-0.9))+(0.2*0.59)
p_a_plus_b
## [1] 0.198
# Answer-13-c: [1] 0.198
** END **