#probability of having red marble getting selected
p_red <- 54/(54+9+75)
# probability of blue marble getting selected .
p_blue <- 75/(54+9+75)
# pr0bability of either red or blue marble getting selected
p_red_blue <- p_red + p_blue
round(p_red_blue,4)
## [1] 0.9348
#probablitiy of getting red ball out of all balls.
p_red <- round(20/(20+24+17+19),4)
p_red
## [1] 0.25
# To prove it programmtically we can run a sample(10k) and select radomly only red ball and calculate the check if probabilty comes close by what we calculated above.
golf_balls <- vector()
golf_balls[1:19] <- "G" # first 19 balls are GREEN
golf_balls[20:39] <- "R" # next 20 balls are RED
golf_balls[40:63] <- "B" # next 24 balls are BLUE
golf_balls[64:80] <- "Y" # next 17 balls are YELLOW
findProb <- function(x,sam_size){
count <- 0
for(i in 1:sam_size){
selected_ball <- sample(golf_balls,1,replace=TRUE)
#print(selected_ball)
if(!is.na(selected_ball) && x == selected_ball){
count <- count+1
}
}
# probability of finding x from sample size of sam_size is
return (count/sam_size)
}
n<- 10000
findProb("R",n)
## [1] 0.2513
data.frame(Housing= c("Apartment","Dorm","With Parent(s)","Sorority/Fraternity House","Other"),Males= c(81,116,215,130,129),Females= c(228,79,252,97,72))
## Housing Males Females
## 1 Apartment 81 228
## 2 Dorm 116 79
## 3 With Parent(s) 215 252
## 4 Sorority/Fraternity House 130 97
## 5 Other 129 72
#P(!Male ???!LWP)=P(!Male)+P(!LWP)???P(!Male ??? !LWP) where
# !M = not male
# !P = not living with parents
#finding probability of not male
p_not_male <- round((228+79+252+97+72)/1399,4)
p_not_male
## [1] 0.5204
#finding probability of male+female not living with parents
p_notLiving_parents <- round((81+116+130+129+228+79+97+72)/1399,4)
p_notLiving_parents
## [1] 0.6662
#finding probability of females not living with parents as that is to be deducted as it is calcuated twice(i.e. intersection).
p_female_NLWP <- round((228+79+97+72)/1399,4)
p_female_NLWP
## [1] 0.3402
#putting into the P(!Male ???!LWP)=P(!Male)+P(!LWP)???P(!Male ??? !LWP)
prob_notM_notLWP <- p_not_male + p_notLiving_parents - p_female_NLWP
prob_notM_notLWP
## [1] 0.8464
Ans :- Dependent.
# Using C(n,k)=n!(n???k)!k!
# use factorial or choose function of r
tot_no <- choose(8,3) * choose(7,3) * choose(3,1)
tot_no
## [1] 5880
Ans:- Indepedent
factorial(14)/factorial(14-8)
## [1] 121080960
round(choose(9,0)*choose(4,1)*choose(9,3)/choose(22,4),4)
## [1] 0.0459
factorial(11)/factorial(7) # 11*10*8*7*6*5*4*3*2*1/ 7*6*5*4*3*2*1 = 11*10*9*8=7920
## [1] 7920
Ans :- This means that 1-(.67) = .33% i.e. 33% users under ages 34 are subscribers to fitness magazine.
#STEP 1:-
# First calculate the probability of 3 heads of 4 toss with probability of heads truning up for each coin flip is 0.5
prob_win <- dbinom(3, size = 4, prob = 0.5)
prob_loss <- 1-prob_win
prop_val <- round(97*prob_win - 30*prob_loss,2)
print(paste("Expected probability to win is :- ",prop_val))
## [1] "Expected probability to win is :- 1.75"
#STEP2
round(559*prop_val,2)
## [1] 978.25
# STEP1
prob_win <- pbinom(4, size = 9, prob = 0.5)
prob_loss <- 1-prob_win
prop_val <- round(23*prob_win - 26*prob_loss,2)
print(paste("Expected probability to win is :- ",prop_val))
## [1] "Expected probability to win is :- -1.5"
#STEP2
round(994*prop_val,2)
## [1] -1491
# Calculating the False Positives , True positive ,False Negative & True Negative values
sensitivity <- 0.59
specificiity <- 0.90
p_liar <- 0.2
p_truth <- 1-p_liar
p_detect_liar <- sensitivity * p_liar
p_detect_truth <- specificiity * p_truth
p_false_detect_liar <- (1-sensitivity)*p_liar
p_false_detect_truth <- (1-specificiity)*p_truth
round(p_detect_liar /(p_detect_liar + p_false_detect_truth),4)
## [1] 0.596
round(p_detect_truth / (p_detect_truth + p_false_detect_liar),4)
## [1] 0.8978
Ans :- P(A???B)=P(A)+P(B)???P(A???B) i.e P(Liar???Detected) = P(Liar) + P(Detected) - P(Liar ??? Detected)
p_liar + (p_detect_liar+p_false_detect_truth) - (p_detect_liar)
## [1] 0.28