ASSIGNMENT 5

Question

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

Answer

Creating two random variables, B and C, by sampling 100,000 numbers between 0 and 1.

n <- 100000

# Take sample of 100,000 random numbers from uniform distribution with min = 0 and max =1
B <- runif(n, min = 0, max = 1)
Bdf <- as.data.frame(B)
DT::datatable(Bdf, options = list(pagelength=5))

#Proof that B has proper probability distributions
ggplot2::ggplot(Bdf, ggplot2::aes(B)) +
  geom_density(color="darkblue", fill="lightblue") +
  theme_minimal() +
  labs(title = "Proper Probability Distributions",
       x = "All the probabilities is between 0 and 1 inclusive",
       y = "Sum of the probabilities of the outcome is 1")

# Take sample of 100,000 random numbers from uniform distribution with min = 0 and max =1
C <- runif(n, min = 0, max = 1)
Cdf <- as.data.frame(C)
DT::datatable(Cdf, options = list(pagelength=5))

#Proof that C has proper probability distributions
Cdf %>%
  ggplot(aes(C)) +
  geom_density(color="#E69F00", fill="#56B4E9") +
  theme_minimal() +
  labs(title = "Proper Probability Distributions",
       x = "All the probabilities is between 0 and 1 inclusive",
       y = "Sum of the probabilities of the outcome is 1")

Uniform density when we plot B and C. The range of both values is between 0 and 1.

(a) B + C < 1/2.

# Create an array with the sum of B and C, and plot the density
sum_BC <- B + C
sum_BCdf <- as.data.frame(sum_BC)
ggplot(sum_BCdf, aes(sum_BC)) + 
  geom_density() +
  labs(title = "Density Plot of B + C", x = "Sum of Random Values")

Similar result when we use the punif function to calculate the probability of B+C<0.5 given a uniform distribution.

prob_a <- sum(punif((B+C)<0.5, min=0, max=1)) / n
print(sprintf("The probability that B + C < 1/2 is %f percent", prob_a*100))
## [1] "The probability that B + C < 1/2 is 12.504000 percent"

The probability that the sum of B and C falls below 12 is about 12.504%.

(b) B x C < 1/2.

# Create an array with the product of B times C, and plot of the density
prod_BC <- B * C
prod_BCdf <- as.data.frame(prod_BC)
ggplot(prod_BCdf, aes(prod_BC)) + 
  geom_density() +
  labs(title = "Density Plot of B * C", x = "Product of Random Values")

# Calculate the probability that B * C < 0.5
prob_b <- sum(punif((B*C)<0.5, min=0, max=1))/n
print(sprintf("The probability that B x C < 1/2 is %f percent", prob_b*100))
## [1] "The probability that B x C < 1/2 is 84.660000 percent"

Probability that the product of B and C falls below \[1/2\] is about 84.66%.

(c) |B - C| < 1/2

# Create an array with the difference of B - C, and plot of the density
diff_BC <- abs(B - C)
diff_BCdf <- as.data.frame(diff_BC)
ggplot(diff_BCdf, aes(diff_BC)) + 
  geom_density() +
  labs(title = "Density Plot of |B - C|", x = "Difference of Random Values")

# Calculate the probability that |B - C| < 0.5
prob_c <- sum(punif((abs(B-C))<0.5, min=0, max=1))/n
print(sprintf("The probability that |B - C| < 1/2 is %f percent", prob_c*100))
## [1] "The probability that |B - C| < 1/2 is 75.222000 percent"

Probability that the difference of B and C falls below 1/2 is about 75.222%.

(d) max{B,C} < 1/2.

# Create an array with the difference of B - C, and plot of the density
max_BC <- pmax(B,C)
max_BCdf <- as.data.frame(max_BC)
ggplot(max_BCdf, aes(max_BC)) + 
  geom_density() +
  labs(title = "Density Plot of max{B,C}", x = "Maximum of Random Values")

# Calculate the probability that max(B,C) < 0.5
prob_d <- sum(punif((pmax(B,C))<0.5, min=0, max=1))/n
print(sprintf("The probability that max{B,C} < 1/2 is %f percent", prob_d*100))
## [1] "The probability that max{B,C} < 1/2 is 25.041000 percent"

Probability that the maximum value of either B or C falls below 1/2 is about 25.041%.

(e) min{B,C} < 1/2.

# Create an array with the difference of B - C, and plot of the density
min_BC <- pmin(B,C)
min_BCdf <- as.data.frame(min_BC)
ggplot(min_BCdf, aes(min_BC)) + 
  geom_density() +
  labs(title = "Density Plot of min{B,C}", x = "Minimum of Random Values")

# Calculate the probability that min(B,C) < 0.5
prob_e <- sum(punif((pmin(B,C))<0.5, min=0, max=1))/n
print(sprintf("The probability that min{B,C} < 1/2 is %f percent", prob_e*100))
## [1] "The probability that min{B,C} < 1/2 is 74.925000 percent"

Probability that the minimum value of either B or C falls below 1/2 is 74.925%.