Theorical part

Join density

We have the uniform distribution of the random vector \((X,Y)^T\) over the set \(M=\{(x,y)\in \mathbb{R}^2 ; 0<x<y<1 \}\).

We know that the density function of a random vector \(Z\) who follows an uniform distribution on a set \(D\) has the form :

\(f_{Z}(z) = 1/(Area(D)) * \mathbb{1}_{z \in D}(z)\)

Therefore, the density function of the random vector \((X,Y)^T\) is :

\[ f_{(X,Y)} (x,y) = 1/(Area(M)) * \mathbb{1} _{(x,y) \in M}(x,y)\] \[ f_{(X,Y)} (x,y) = 1/(1/2) * \mathbb{1} _{(x,y) \in M} (x,y)\] \[ f_{(X,Y)} (x,y) = 2 * \mathbb{1} _{(x,y) \in M}(x,y)\]

Marginal densities

We can now find the marginal densities of the random vectors \(X\) and \(Y\).

\(f_{X}(x) = \int f_{(X,Y)} (x,y) \, \mathrm{d}y\)

\(f_{X}(x) = \int 2 * \mathbb{1} _{(x,y) \in M}(x,y) \, \mathrm{d}y\)

\(f_{X}(x) = \int_x^1 2 * \mathbb{1}_{0<x<y}(x) \mathrm{d}y\)

\(f_{X}(x) = [2y]_x^1 * \mathbb{1}_{0<x<y}(x)\)

\(f_{X}(x) = (2 - 2x) * \mathbb{1}_{0<x<y}(x)\)

Similarly, we can calculate the marginal density of \(Y\) :

\(f_{Y}(y) = \int f_{(X,Y)} (x,y) \, \mathrm{d}x\)

\(f_{Y}(y) = \int 2 * \mathbb{1} _{(x,y) \in M}(x,y) \, \mathrm{d}x\)

\(f_{Y}(y) = \int_0^y 2 * \mathbb{1}_{x<y<1}(y) \mathrm{d}x\)

\(f_{Y}(x) = [2y]_0^y * \mathbb{1}_{x<y<1}(y)\)

\(f_{Y}(x) = 2y * \mathbb{1}_{x<y<1}(y)\)

Independance ?

The first hinch is to say that \(X\) and \(Y\) can not be independant because the random vector \((X,Y)^T\) is defined on \(M\), and \(M\) is constructed on \(X\) depending on \(Y\) (or on \(Y\) depending on \(X\)).

However, let’s use the theorical definition of independance in a join random vector.

Let’s suppose \((X,Y)^T\) is a join random vector, which density function is \(f_{(X,Y)}(x,y)\). \(X\) and \(Y\) are independant only if : \[f_{(X,Y)}(x,y) = f_{X}(x) * f_{Y}(y)\]

In our case, we have : \[f_{X}(x) * f_{Y}(y)=(2 - 2x) * \mathbb{1}_{0<x<y}(x) * f_{Y}(x) = 2y * \mathbb{1}_{x<y<1}(y) \] \[f_{X}(x) * f_{Y}(y) = (4x-4xy) * \mathbb{1} _{(x,y) \in M}(x,y)\]

Finally, \[f_{X}(x) * f_{Y}(y) \ne f_{(X,Y)} (x,y)\]

Like it seemed to appeared, \(X\) and \(Y\) are not independant from each other.

Practical

Join density

First of all, let’s create a simulation of the random vector \((X,Y)^T\).

n = 10000

x = rep(0,n)
y = rep(0,n)
random = rep(0,n)
for (i in 1:n){
  random = runif(2,0,1)
  x[i] = min(random)
  y[i] = max(random)
}

X_Y = as.data.frame(cbind(x,y))
head(X_Y)
##            x         y
## 1 0.43030475 0.8709449
## 2 0.29464446 0.6755050
## 3 0.01867491 0.5154143
## 4 0.39059473 0.4128779
## 5 0.34326436 0.6737392
## 6 0.28222589 0.6742817

We can now vizualise the joint density and see if it corresponds to our previous calculation. First of all, let’s plot the \(M\) area to be sure it is equal to \(1/2\).

plot(X_Y$x, X_Y$y, type ='c', col ='blue', xlab = "X", ylab = "Y", main = "Vizualisation of M set")

It is surely equal to 1/2.

Let’s vizualise the joint density :

library(ggplot2)
library("MASS")
ggplot(X_Y, aes(x=x, y=y) ) +
  stat_density_2d(aes(fill = ..level..), geom = "polygon")

We can see that the density is equal to 2 almost everywhere on the set M. We surely have found the right density expression for the random vector \((X,Y)\).

Marginal densities

Similarly, we can plot the marginal densities as well as the theorical densities and see how they behave.

To remind, we have found these theorical density functions : \(f_{X}(x) = (2 - 2x) * \mathbb{1}_{0<x<y}(x)\) and \(f_{Y}(x) = 2y * \mathbb{1}_{x<y<1}(y)\).

par(mfrow=c(1,2))

xSeq <- seq(0,1, length = n)

plot(density(x), main = "Density function of X")
lines(2-xSeq*2 ~ xSeq, col = "red", lty = 2, lwd = 2)
legend("topright", legend = c("Empirical d.f.", "Theoretical d.f."), col = c("black", "red"), lty = c(1,2), lwd = c(2,2))

plot(density(y), main = "Density function of Y")
lines(2*xSeq ~ xSeq, col = "red", lty = 2, lwd = 2)
legend("topleft", legend = c("Empirical d.f.", "Theoretical d.f."), col = c("black", "red"), lty = c(1,2), lwd = c(2,2))

Once again, the graphics correspond to our theorical approach which seem right.

To conclude, we can calculate important sample characteristics (sample means and the sample variance-covariance matrix) :

library(corrplot)
## corrplot 0.92 loaded
library("eqs2lavaan")
## Le chargement a nécessité le package : lavaan
## This is lavaan 0.6-10
## lavaan is FREE software! Please report any bugs.
## Le chargement a nécessité le package : stringr
mean(x)
## [1] 0.3343056
mean(y)
## [1] 0.667885
cor(x,y)
## [1] 0.4915037
plotCov(cov(X_Y))

##            x          y
## x 0.05571186 0.02715584
## y 0.49150369 0.05479300