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

library(tidyverse)
library(ggthemes)
set.seed(101)
B <- runif(10000, 0, 1)
C <- runif(10000, 0, 1)

sumVec <- B + C
productVec <- B * C
absVec <- abs(B - C)
maxVec <- pmax(B, C)
minVec <- pmin(B, C)

df <- data.frame(cbind(B, C))
ggplot(df) + 
  geom_histogram(aes(x = df$B), fill = 'grey', alpha = .5, color = 'black')+
  geom_histogram(aes(df$C), fill = 'light blue', alpha = .5, color = 'black') +
  ggtitle('Uniform Density Distrubution') + theme_tufte()

a)

\(B + C < 1/2\) Since B + C is a straight line, the function to integrate over is simply \(x\).

IntagreteBootStrap <- function(vec, integrand){
  ans1 = integrate(integrand, lower = 0, upper = 1/2)$value
  ans2 = ecdf(vec)(.5)
  print(paste('The answer found from integratin is:', ans1, 'The answer found from boot strap is:', ans2))
}
integrand = function(x){x}
IntagreteBootStrap(sumVec, integrand)
## [1] "The answer found from integratin is: 0.125 The answer found from boot strap is: 0.125"

b)

\(BC < 1/2\) \(B\cdot C\)

integrand = function(x){-log(x)}
IntagreteBootStrap(productVec, integrand)
## [1] "The answer found from integratin is: 0.846573590279972 The answer found from boot strap is: 0.8465"

c)

\(|B − C| < 1/2\)

integrand = function(x){2 * (1 - x)} # multiply by 2 because of the positive and neg options.
IntagreteBootStrap(absVec, integrand)
## [1] "The answer found from integratin is: 0.75 The answer found from boot strap is: 0.7466"

d)

\(max(B,C) < 1/2\)

Instead of integrating, we can use more elementary probability theory to solve this. The probability of \(max(B,C) < 1/2\) is given by:

\[ P(B) < 1/2 \cap P(C) < 1/2\] Since \(E(B,C) = \frac{1}{2}, \frac{1}{2}\) The solution is \(\Big ( \frac{1}{2} \Big ) ^2 = \frac{1}{4}\)

length(maxVec[maxVec<.5]) / length(maxVec)
## [1] 0.2524

e)

\(min(B,C) < 1/2\)

Since \(E(B,C) = \frac{1}{2}, \frac{1}{2}\) The solution is \(1 - \Big ( \frac{1}{2} \Big ) ^2 = \frac{3}{4}\)

length(minVec[minVec<.5]) / length(minVec)
## [1] 0.7545