Joint Distributions and Covariance

  • We now consider pairs and vectors of random variables. In general, in a probability spce, we amy define multiple random vairables, , where we consider the vector or tuple, , as a random vector. A key question deals with representing and evaluating probabilities of the form , where is some subset . Our focus here is on the case of a pair of random vairables , which are continuous and have a density function. The probability distribution of is called a bivariate distribution, and more generally the probability of is called a multivariate distribution.

The Joint PDF

  • A function, , is said to be a Joint Probability Density Function (PDF) if for any input, , it holds that and
  • Hence, if we consider now , then the probabilities of a random vector , distributed with density , can be evaluated by

Example

  • Let and consider the joint density, simply denoted ,
  • Set , then
  • We can obtain the marginal densities of and , denoted and :
  • In general, the random vairbles and are said to be independent if . But in our current example, this is not the case. Furthermore, whenever we have two densities of scalar random variables, we may multiply them to make the joint distribution of the random vector composed of independent random varible.
  • Observe that . Hence, while both bivariate distributions have the same marginal distribution, they are different bivariate distributions and hence describe different relationships between and .
  • The conditional density of given . It is denoted by and describes the distribution of the random variable , given the specific value .
  • Simulation by Julia
using Plots, LaTeXStrings, Measures;gr()

delta = 0.01
grid = 0:delta:1
f(x,y) = 9/8*(4x+y)*sqrt((1-x)*(1-y))
z = [f(x,y) for y in grid, x in grid]

densityIntegral = sum(z)*delta^2
println("2-dimensional Riemann sum over density: ",densityIntegral)

probB = sum([sum([f(x,y)*delta for y in x:delta:1])*delta for x in grid])
println("2-dimensional Riemann sum to evaluate probability: ", probB)

p1 = surface(grid, grid, z,
    c=cgrad([:blue, :red]), la=1, camera=(60,50),
    ylabel="y", zlabel=L"f(x,y)", legend=:none)
p2 = contourf(grid, grid, z,
    c=cgrad([:blue, :red]))
p3 = contour!(grid, grid, z,
    c=:black, xlims=(0,1), ylims=(0,1), ylabel="y", ratio=:equal)

plot(p1,p2, size=(800, 400), xlabel="x", margin=5mm)

Covariance and Vectorized Moments

  • Given two random variables, and , with respective means, and , the covariance is defined by
  • The covariance is a common measure of the relationship between the two random variables, where if , we say the random variable are unrelated. Furthermore, if , the sign of the covariance gives an indication of the direction of the relationship.
  • The correlation coefficient is
  • It is a normalized form of the covariance with . Values nearing indicate a very strong linear relationship between and , whereas values near or at indicate a lack of a linear relationship.
  • Note that if and are independent random variables, then and hence . However, the opposite case does not always hold, since, in general, does not imply indepenence. Nevertheless as described below, for jointly normal random variables it does.
  • Consider a random vector , taken as a column vector. It can be described by moments in an analogous manner to a scalar random variable. A key quantity is the mean vector,
  • Furthermore, the covariance matrix is the matrix defined by the expectation of the random matrix given by , and is expressed as
  • The , -th element of is and hence the diagonal elements are the variances.

Linear Combinations and Transform

  • The linear transformations applied to random vectors. For any collection of random variables,
  • For uncorrelated random variables,
  • More generally, if we allows the random variables tobe correlated, then
  • Note that the right-hand side of forluma above is the sum of the elements of the matrix . This is a special case of a more general affine transformation, where we take a random vector with covariance matrix , and an matrix and vector , we then set
  • In this case, the new random vector exhibits mean and covariance

The Cholesky Decomposition and Generating Random Vectors

  • Suppose that you wish to create an -dimensional random vector with some specified mean vector and covariance matrix . That is, and are known.
  • If we are given a random vector with zero-mean and identity-covariance matrix . And apply the affine transformation on with and a matrix that satisfies
  • The question is now how to find a matrix . For this the Cholesky decomposition comes as an aid and finds a matrix .
  • As an example assume we wish to generate a random vector with
  • Solution by Julia
using Distributions, LinearAlgebra, LaTeXStrings, Random, Plots; pyplot()
Random.seed!(1)

N = 10^5

SigY = [6 4;
    4 9]
muY = [15;
    20]
A = cholesky(SigY).L

rngGens = [ ()->rand(Normal()),
            ()->rand(Uniform(-sqrt(3),sqrt(3))),
            ()->rand(Exponential())-1]

rv(rg) = A*[rg(), rg()] + muY

data = [[rv(r) for _ in 1:N] for r in rngGens]

stats(data) = begin
    data1, data2 = first.(data), last.(data)
    println(round(mean(data1), digits=2),"\t",round(mean(data2),digits=2), "\t",
    round(var(data1),digits=2),"\t", round(var(data2),digits=2), "\t",
    round(cov(data1, data2), digits=2))
end

println("Mean1\tMean2\tVar1\tVar2\tCov")
for d in data
    stats(d)
end

scatter(first.(data[1]), last.(data[1]), c=:blue, ms=1, msw=0, label="Normal")
scatter!(first.(data[2]), last.(data[2]), c=:red, ms=1, msw=0, label="Uniform")
scatter!(first.(data[3]), last.(data[3]), c=:green, ms=1, msw=0, label="Exponential",
    xlims=(0,40), ylims=(0,40), legend=:bottomright, ratio=:equal,
    xlabel=L"X_1", ylabel=L"X_2")

Bivariate Normal

  • Similartly to the fact that a scalar (univariate) normal distribution is parameterized by the mean and variance , a multivariate normal distribution is parameterized by the mean vector and the covariance matrix
  • We begin first with the standard multivairate having and . In this case, the PDF for the random vector is
using HCubature

M = 4.5
maxD = 10

f(x) = (2*pi)^(-length(x)/2)*exp(-1/2*x'x)

for n in 1:maxD
    a = -M*ones(n)
    b = M*ones(n)
    I,e = hcubature(f, a, b, maxevals = 10^7)
    println("n = $(n), integral = $(I), error (estimate) = $(e)")   
end
  • In general, using an affine transformation, it can be shown that for arbitrary and ,
  • In the case of , this becomes the bivarate normal distribution with a density represented as
  • Here the elements of the mean and covariance matrix is
using Distributions, Plots; pyplot()

include("../data/mvParams.jl")
biNorm = MvNormal(meanVect, covMat)

N = 10^3
points = rand(MvNormal(meanVect, covMat), N)

support = 15:0.5:40
z = [ pdf(biNorm, [x,y]) for y in support, x in support]

p1 = scatter(points[1,:], points[2,:], ms=0.5, c=:black, legend=:none)
p1 = contour!(support, support, z,
    levels=[0.001, 0.005, 0.02], c=[:blue, :red, :green],
    xlims=(15,40), ylims=(15,40), ratio=:equal, legend=:none,
    xlabel="x", ylabel="y")
p2 = surface(support, support, z, lw=0.1, c=cgrad([:blue, :red]),
    legend=:none, xlabel="x", ylabel="y", camera=(-35,20))

plot(p1,p2, size=(800,400))

results matching ""

    No results matching ""