You are on page 1of 50

Budi Yuniarto, SST, M.

Si
Pertemuan IV
Bivariate Normal Distribution
• The generalization of the well-
known normal distribution to
multiple variables is called the
multivariate normal distribution
(MVN).
• Many multivariate techniques rely
on this distribution in some manner.
• Although real data may never come
from a true MVN, the MVN provides
a robust approximation, and has
many nice mathematical properties.
• Furthermore, because of the central
limit theorem, many multivariate
statistics converge to the MVN
distribution as the sample size
increases.
> library(rgl)
> library(plot3D)
> library(plot3Drgl)
> library(squash)
> library(MASS)

> ## Simulate data:


> mu<-c(0,0)
> Sig<-matrix(c(1,0,0,1),nrow = 2,byrow = TRUE)
> bvn1 <- mvrnorm(500, mu = mu, Sigma = Sig )

> #scatterplot
> plot(bvn1[,1],bvn1[,2],pch=20)
> smoothScatter(bvn1[,1],bvn1[,2],colramp = rainbow2)

> ## Create cuts:


> x_c <- cut(bvn1[,1], 20)
> y_c <- cut(bvn1[,2], 20)

> ## Calculate joint counts at cut levels:


> z <- table(x_c, y_c)

> ## Plot as a 3D histogram:


> hist3D(z=z, border="black")
> hist3Drgl(z=z, border="black")
> hist2(x_c,y_c, key.args = list(stretch = 2))
• The lines of the contour plots denote places of
equal probability mass for the MVN distribution.
• These contours can be constructed from the
eigenvalues and eigenvectors of the covariance
matrix.
– The direction of the ellipse axes are in the direction of the
eigenvalues.
– The length of the ellipse axes are proportional to the
constant times the eigenvector.
Illustration: Probability Contours
Example 1
Confidence Region:

95%

(-1.22 , 1.22)
(2.12 , 2.12)
Example 2
Major axis
Minor axis
> library(mixtools)
> library(MASS)

> mu1<-c(5,10)
> Sig1<-matrix(c(9,16,16,64),nrow = 2)

> # Function to draw ellipse for bivariate normal data


> ellipse_bvn <- function(bvn, alpha){
> Xbar <- apply(bvn,2,mean)
> S <- cov(bvn)
> ellipse(Xbar, S, alpha = alpha, col="red")
> }

> #generate random bvn


> bvn <- mvrnorm(500, mu = mu1, Sigma = Sig1 )

> plot(bvn,xlab="X1",ylab="X2")
> ellipse_bvn(bvn,.5)
> ellipse_bvn(bvn,.1)
> ellipse_bvn(bvn,.05)
Example 3
95% Confidence
Region:
If X has a multivariate normal distribution, then:

1. Linear combinations of X are normally distributed.

2. All subsets of the components of X have a MVN distribution.

3. Zero covariance implies that the corresponding components


are independently distributed.

4. The conditional distributions of the components are MVN.


Illustration with Multiple Combinations
Illustration
Illustration
Illustration by
Picture

X
f(X|Y=50)

f(X|Y=30)
Just a review
Multivariate Case
Sampling Distribution of ∑
Law of Large Numbers
Central Limit Theorem
ASSESSING MULTIVARIATE
NORMALITY
qj = (j–.5)/n, j = 1, 2,..., n.
Exercise

You might also like