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.
To answer this question : First I will get some distrbutions out of the way for the entire assignment; including B and C.
n=30000
bee_vector = sapply((vector(length=n,mode='numeric')+1),runif)
cee_vector = sapply((vector(length=n,mode='numeric')+1),runif)
sum_vector = bee_vector+cee_vector
product_vector = bee_vector*cee_vector
abs_vector = abs(bee_vector - cee_vector)
max_vector = pmax(bee_vector,cee_vector)
min_vector = pmin(bee_vector,cee_vector)
collab = list(bee_vector,cee_vector,sum_vector,product_vector,abs_vector,max_vector,min_vector)
Awesome, lets look at B and C
hist(bee_vector,freq=FALSE,main = 'B distribution' )
lines(density(bee_vector))
hist(cee_vector,freq=FALSE,main = 'C distribution' )
lines(density(cee_vector))
Both distributions of B and C follow conform to the unfiform, rectangular distribution.
Question (A) Find the probability that : B + C < 1/2.
The function that contains the area of A+B is f(z) for all values under 1; and since we only go up to 0.5 ….
integrand = function(x) {x}
qa = integrate(integrand, lower = 0, upper = 1/2)
#Test our calculus against the bootstrapped answer
bs = ecdf(sum_vector)
print(c(qa$value,'vs',bs(.5)))
## [1] "0.125" "vs" "0.125633333333333"
Question (B) Find the probability that : BC < 1/2.
The product of two uniform variables of the same interval, is basically multiplied by itself…Meaning exponential distribution.
integrand = function(x) {-log(x)}
qb =integrate(integrand, lower = 0, upper = 1/2)
bs = ecdf(product_vector)
print(c(qb$value,'vs',bs(.5)))
## [1] "0.846573590279972" "vs" "0.848"
Question (C) Find the probability that : |B - C| < 1/2.
integrand = function(x) {2*(1-x)}
qc =integrate(integrand, lower = 0, upper = 1/2)
bs = ecdf(abs_vector)
print(c(qc$value,'vs',bs(.5)))
## [1] "0.75" "vs" "0.751166666666667"
Question (D) + (E) Find the probability that : min(B,C) < 1/2 & max(B,C) < 1/2 :
Looking at the graphs at the bottom of this assignment; you will see that both min and max of B,C are equivalent to the distribution of |B-C| with max being inverse.
minCDF = ecdf(min_vector)
absCDF = ecdf(abs_vector)
print( c(minCDF(.5),'vs', absCDF(.5) ))
## [1] "0.751333333333333" "vs" "0.751166666666667"
Since Max{B,C} is distributed inversely to Min{B,C}
maxCDF = ecdf(max_vector)
print(c(maxCDF(.5),'vs', 1-qc$value ) )
## [1] "0.251633333333333" "vs" "0.25"
names = c('B','C','B+C','BC','|B-C|','max{B,C}','min{B,C}')
bothersome_variable_used_for_titles = 0
for(x in collab){
bothersome_variable_used_for_titles = bothersome_variable_used_for_titles + 1
hist(x,freq=FALSE,main = names[bothersome_variable_used_for_titles] )
lines(density(x))
plot(ecdf(x))
}