#create 1k random values for B
B_value <- runif(1000, min = 0, max = 1)
#create 1k random values for C
C_value <- runif(1000, min = 0, max = 1)
B <- as.data.frame(B_value)
C <- as.data.frame(C_value)
In order to prove that B and C are proper probability distributions we have to prove that 1. All the probabilities must be between 0 and 1 inclusive 2. The sum of the probabilities of the outcomes must be 1.
#add up values for 1k rows
sum_b <- B %>% summarise(sum_all=sum(B_value))
sum_c <- C %>% summarise(sum_all=sum(C_value))
#verify that probabilities must be between 0 and 1 inclusive
num_b <- B %>% mutate(is_btw_1_and_0 = ifelse(B_value > 0 && B_value <= 1,TRUE,FALSE)) %>% group_by(is_btw_1_and_0) %>% tally()
num_c <- C %>% mutate(is_btw_1_and_0 = ifelse(C_value > 0 && C_value <=1,TRUE,FALSE)) %>% group_by(is_btw_1_and_0) %>% tally()
paste("B: ",num_b[2], " values out of ", nrow(B)," values are between 0 and 1 inclusive")
## [1] "B: 1000 values out of 1000 values are between 0 and 1 inclusive"
paste("C: ",num_c[2], " values out of ", nrow(C)," values are between 0 and 1 inclusive")
## [1] "C: 1000 values out of 1000 values are between 0 and 1 inclusive"
#verify that the sum of the probabilities of the outcomes must be 1
outcome_b <- B %>% mutate(prob_b=B_value/sum_b[1,1]) %>% summarise(sum(prob_b))
outcome_c <- C %>% mutate(prob_c=C_value/sum_c[1,1]) %>% summarise(sum(prob_c))
paste("B: the sum of the probabilities of the outcomes is ",outcome_b)
## [1] "B: the sum of the probabilities of the outcomes is 1"
paste("C: the sum of the probabilities of the outcomes is ",outcome_c)
## [1] "C: the sum of the probabilities of the outcomes is 1"
Both conditions are satisfied. It means that B and C have proper probabilities.
Find the probability that
sum((B$B_value + C$C_value) < 1/2)/nrow(B)
## [1] 0.105
sum(B$B_value*C$C_value < 1/2)/nrow(B)
## [1] 0.847
sum(abs(B$B_value + C$C_value) < 1/2)/nrow(B)
## [1] 0.105
sum(pmax(B, C) < 1/2)/nrow(B)
## [1] 0.237
sum(pmin(B, C) < 1/2)/nrow(B)
## [1] 0.755