Homework Assignment 5

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.

# runif(n) generates n uniform random numbers between 0 and 1
B <- runif(100000)
C <- runif(100000)
# generate tibble with data
df <- tibble(
  B = B,
  C = C
)

# cleanup tibble
df <- df%>%
  rename(simB = 1)%>%
  rename(simC = 2)
head(df)
## # A tibble: 6 x 2
##    simB  simC
##   <dbl> <dbl>
## 1 0.716 0.251
## 2 0.721 0.834
## 3 0.112 0.727
## 4 0.816 0.617
## 5 0.390 0.695
## 6 0.612 0.599

Find the probability that

1. B + C < 1/2

p = 0
for(i in 1:length(B)){
  if(B[i]+C[i] < 0.5){
    p = p+1
  }
}
print (paste("Question 1,where B+c < 1/2=",p/length(B)))
## [1] "Question 1,where B+c < 1/2= 0.12487"

2. BC < 1/2

p = 0
for(i in 1:length(B)){
  if(B[i]*C[i] < 0.5){
    p = p+1
  }
}
print (paste("Question 2,where BC < 1/2=",p/length(B)))
## [1] "Question 2,where BC < 1/2= 0.8481"

3. |B − C| < 1/2

p = 0
for(i in 1:length(B)){
  if(abs(B[i]-C[i]) < 0.5){
    p = p+1
  }
}
print (paste("Question 3,where |B-C|< 1/2=",p/length(B)))
## [1] "Question 3,where |B-C|< 1/2= 0.75261"

4. max{B,C} < 1/2

p = 0
for(i in 1:length(B)){
  if(max(B[i],C[i]) < 0.5){
    p = p+1
  }
}
print (paste("Question 4,where max{B,C} < 1/2=",p/length(B)))
## [1] "Question 4,where max{B,C} < 1/2= 0.25203"
q4 <- p/length(B)

5. min{B,C} < 1/2

p = 0
for(i in 1:length(B)){
  if(min(B[i],C[i]) < 0.5){
    p = p+1
  }
}
print (paste("Question 5,where min{B,C} < 1/2=",p/length(B)))
## [1] "Question 5,where min{B,C} < 1/2= 0.74969"
q5 <- p/length(B)