Please write the program In R don\'t copy and paste it from any other source bec
ID: 2925705 • Letter: P
Question
Please write the program In R don't copy and paste it from any other source because they are not what I"m looking for follow the directions below:
For the below exercise use R to simulate the process of generating pairs of (X,Y) values and estimate the probability that Y-X is at least 1/2. please write the code used in R to find this. exercise is described below:
exercise: X and Y are two independednt and identically distributed continous random variables. The probabilty density function of X is fx(x) = { 3x^2, 0 <= x <=1,
0, otherwise}
That of Y is a similarly defined as that of X. Write down the joint probabilty density function of X and Y and find the probabilty that PROB{X-Y >= 1/2}.
fY(y) is exactly the same as fx(x) only y replaces the x.
data:
f(x,y) = { 9x^(2)y^(2) , if 0< x <1 and if 0 < y < 1
0, otherwise }
use computer to generate samples (xi, yi) with a starting point of n =20 and a ending point 5000, which will allow it to easily be made into a table such as this for every single value program should be able: to print a way for every single value of from n=20 to n = 5000 and I do mean every single one an example looks like this:
n Pn
20 P20 = 0.3
21 P21 = 0.27
. .
. .
5000 P5000= ?
theortical value = 0.03828125
Explanation / Answer
The code is pretty simple;
Steps:
1. Generate standard Unifrom random variables U1 , U2
2. Invert them since Fx(x) = x3.... So from transformation of variable rule,
we get x = U11/3 and y= U21/3
And then check if x-y >= 0.5 or not.
Calculate the proportion : How many times x-y >= 0.5 happens and that is your probability P ( X-Y > = 0.5 )
Code: (Note that values will change each time you run the code , since this is simulation and randomness involved)
prob <- function(n)
{
#Generating Uniform(0,1)
u1 <- runif(n)
u2 <- runif(n)
# Inverting since CDF of X is F(x) = X^3
x <- u1**(1/3)
y <- u2**(1/3)
#calculating proportions of how many of them >=0.5
probability <- mean(ifelse(x-y >=.5,1,0))
pn <- paste('P',n)
t<- c(n, pn, probability)
return(t)
}
l<- seq(20,5000)
View(t(data.frame(sapply(l,prob))))
A table will pop up and you have the answer!!.