library(pracma)
library(ggplot2)
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.
#randomly select 10,000 numbers between 0 and 1
B <- runif(10000, min = 0, max = 1)
head(B)
## [1] 0.1741111 0.4697572 0.6350868 0.1450765 0.6196762 0.6852390
C <- runif(10000, min = 0, max = 1)
head(C)
## [1] 0.5695273 0.5883954 0.3537465 0.3298146 0.7002650 0.2014524
head(B+C)
## [1] 0.7436384 1.0581526 0.9888333 0.4748910 1.3199413 0.8866914
All values of B and C are between 0 and 1 and sum of the probabilites of each value in B and C is less than 1.
Let us plot the density functions for B and C. We see that both are uniform density functions with values ranging from 0 to 1
B_data<-as.data.frame(B)
C_data<-as.data.frame(C)
ggplot(B_data, aes(x=B)) +
geom_density() +
labs(title = "Density Plot of Random Value B (n = 10,000)", x = "Random Values")
ggplot(C_data, aes(x=C)) +
geom_density() +
labs(title = "Density Plot of Random Value C (n = 10,000)", x = "Random Values")
Find the probability that
\[P(B+C<1/2)=P(X+Y<1/2)=P(0<X<1/2,0<Y<1/2−x)\]
a <- sum((B+C) < .5)/10000
print("The probability that B+C will be less than 1/2 is")
## [1] "The probability that B+C will be less than 1/2 is"
print(a)
## [1] 0.1316
\[P(B,C<1/2)\]
b <- (sum((B*C) < .5)/10000)
print("The probability that B*C will be less than 1/2 is")
## [1] "The probability that B*C will be less than 1/2 is"
print(b)
## [1] 0.8497
\[P(|X−Y|< 1/2 , 0<x+y<1) = P(−1/2<X−Y<1/2 ; 0< X< 1−Y)\]
c <- sum(abs((B-C)) < .5)/10000
print("The probability that |B-C| will be less than 1/2 is")
## [1] "The probability that |B-C| will be less than 1/2 is"
print(c)
## [1] 0.7476
\[P(max(B,C)<1/2)=P(B<=1/2,C<=1/2)\]
x <- 0
for(i in 1:10000){
if(max(c(B[i],C[i])) < 0.5){
x = x+1
}
}
d <- x/10000
print("The probability that max{B,C} will be less than 1/2 is")
## [1] "The probability that max{B,C} will be less than 1/2 is"
print(d)
## [1] 0.2596
min{B,C} < 1/2
\[P(min(B,C)<=1/2)=1−P(B>1/2,C>1/2)\]
x <- 0
for(i in 1:10000){
if(min(c(B[i],C[i])) < 0.5){
x = x+1
}
}
e <- x/10000
print("The probability that min{B,C} will be less than 1/2 is")
## [1] "The probability that min{B,C} will be less than 1/2 is"
print(e)
## [1] 0.7592