Consider this very simple snippet:
m1 <- 0
m2 <- 0
cov <- 0.8
x1 <- rnorm(100, mean=m1)
x2 <- cov*x1 + rnorm(100,mean=m2-cov*m1,sd=sqrt(1-cov*cov))
plot(x1,x2)
x2a <- x2*sign(x1-m1)*sign(x2-m2)
plot(x1,x2a)
It folds the distribution of x2
around its mean, aligning its deviations from the mean to those of x1
from its mean. Of course the resulting distribution cannot be characterized as a multivariate normal, although each margin is normal:
plot( density(x1), ylim=c(0,0.5) )
hist( x1, add=T, prob=T )
Contours of the density of (x1, x2a): the probability that would ordinarily be associated with values in quadrants II or IV has been symmetrically displaced into quadrants I and III, leaving the marginal distributions undisturbed.
This is a classic (counter)example of a distribution that has normal margins, yet is not a multivariate normal; frankly, I don't know how to build any other ones.
The transformation increases the correlation somewhat:
> cor(x1,x2)
[1] 0.7999774
> cor(x1,x2a)
[1] 0.8575814
You would've seen a much stronger effect with lower cov
, of course: you can start with cov=0
and still get the correlation of the resulting variables above 0.6.
Best Answer
Wikipedia introduces the method of drawing values from the distribution. I am now trying to illustrate it in more details.
If we want to draw sample from the multivariate normal distribution specified by $\mu \in \mathbb{R}^{n\times 1}$ and $\Sigma \in \mathbb{R}^{n\times n}$ and $\Sigma^\top = \Sigma$. We can do the following to generate random variable $\mathbf{x} \in \mathbb{R}^{n\times 1}$ such that $\mathbf{x} \sim \mathcal{N}(\mu, \Sigma)$.
randn(n, 1)
function in Matlab to generate $n$ independent standard normal variables and get a random vector $\mathbf{z} \in \mathbb{R}^{n \times 1}$, and $\mathbf{x} = \mu + A \mathbf{z}$ is what we want.Julia code for this is
We now verify that data generated in this way satisfies that $$\mathbf{x} \sim \mathcal{N}(\mu, \Sigma)$$ As $\mathbf{z} \sim \mathcal{N}(0, 1)$, from affine transformation of multivariate normal distribution we know that $\mathbf{x} = \mu + A \mathbf{z}$ indeed satisfies the needed property.