Choose independently two numbers B and C at random from the interval [0, 1] with uniform density. Prove that B and C are proper probability distributions. Note that the point (B,C) is then chosen at random in the unit square.
Find the probability that
B + C < 1/2.
BC < 1/2.
|B - C| < 1/2.
max{B,C} < 1/2.
min{B,C} < 1/2.
Prove that B and C are proper probability distributions.
# generate random numbers from a uniform distribution
set.seed(NULL)
B <- runif(10000, min = 0, max = 1)
set.seed(NULL)
C <- runif(10000, min = 0, max = 1)
df_b<- as.data.frame(B)
# check whether the probability of B is between 0 and 1
# firsr create a series with all the values as False
sum_p <- rep(F,times=length(B))
# then calculate the pribability of B
for (i in 1:length(B)){
x=1
for (j in 1:length(B)){
if (j != i && B[i] == B[j]){
x <- x + 1
}
}
p <- x/length(B)
# if the probability is between and 1 inclusive, the value in sum_p will change to True correspondingly
sum_p[i] <- (0 <= p && p<= 1)
}
condition_1 <- !any(sum_p == F)
print(paste("Is all the probabilities of B is between 0 and 1 inclusive? ",condition_1 ))
## [1] "Is all the probabilities of B is between 0 and 1 inclusive? TRUE"
print(paste("Similarly, all the probabilities of B is between 0 and 1 inclusive "))
## [1] "Similarly, all the probabilities of B is between 0 and 1 inclusive "
# sum the probability of B and denote as sigma
sigma_b <- 0
for (i in 1:length(B)){
x=1
for (j in 1:length(B)){
if (j != i && B[i] == B[j]){
x <- x + 1
}
}
p <- x/length(B)
sigma_b <- sigma_b + p
}
sigma_b
## [1] 1
sigma_b <- round(sigma_b)
print(paste("The sum of the probabilities of the outcomes of B is",sigma_b))
## [1] "The sum of the probabilities of the outcomes of B is 1"
print(paste("Similarly,The sum of the probabilities of the outcomes of C is",sigma_b))
## [1] "Similarly,The sum of the probabilities of the outcomes of C is 1"
For both B or C, all the probabilities is between 0 and 1 inclusive.
For both B or C,the sum of the probabilities of the outcomes is 1.
So B and C are proper probability distributions
P1 <- sum((B+C) < 1/2)/length(B)
(paste("The probability for B + C < 1/2. is: ",P1))
## [1] "The probability for B + C < 1/2. is: 0.1284"
P2 <- sum((B*C) < 1/2)/length(B)
(paste("The probability for BC < 1/2. is: ",P2))
## [1] "The probability for BC < 1/2. is: 0.8497"
P3 <- sum( abs((B-C)) < 1/2)/length(B)
(paste("The probability for |B - C| < 1/2. is: ",P3))
## [1] "The probability for |B - C| < 1/2. is: 0.7495"
x=0
for (i in 1:length(B)){
if (max(B[i],C[i]) < 1/2){
x=x+1
}
}
P4 <- x/length(B)
(paste("The probability for max{B,C} < 1/2. is: ",P4))
## [1] "The probability for max{B,C} < 1/2. is: 0.2522"
y=0
for (i in 1:length(B)){
if (min(B[i],C[i]) < 1/2){
y=y+1
}
}
P5 <- y/length(B)
(paste("The probability for min{B,C} < 1/2. is: ",P5))
## [1] "The probability for min{B,C} < 1/2. is: 0.7523"