NMST539  Lab Session 2Multivariate Normal DistributionLS 2017  Thursday 02/03/17Rmd file (UTF8 coding)For the second NMST539 lab session we will discover some tools, available within the R software instalation, which are meant for working with the multivariate normal distribution. The Rsoftware is available for download from the website: https://www.rproject.org A userfriendly interface (one of many): RStudio. Manuals and introduction into R (in Czech or English):
R package ‘mvtnorm’For the beginning, we need to make sure that the library for the multivariate normal distribution (
We can now use the loaded library to easily generate random values from some multivariate normal distribution with some prespecified variancecovariance matrix \(\Sigma\). For more details about the library (including the manual document) see the library website on R cran: CommentIt is useful to always keep in mind that everytime we are about to use some random generator in R (or any other software) it is good to predefine the initial values for the generator (in R there is a command called For instance try (among each other) the command:
and compare it with the same commend, however, with the initial setting of the generator done by the
Is it clear, what is the difference between these two outputs?
For the beginning, let us start with a simple (twodimensional only) example: we will generate a random sample of size \(n \in \mathbb{N}\) from the twodimensional normal distribution \(N_{2}\Big(\boldsymbol{\mu} = \Big(\begin{array}{c}2\\3\end{array}\Big), \Sigma = \Big(\begin{array}{cc}10^2 & 6^2\\ 6^2 & 6^2\end{array}\Big) \Big)\). Remember, that in case of a onedimensional random generator for the normal distribution in R (command The sample of size \(n=1000\) from the given twodimensional normal distribution can be generated by the following command:
And we can plot the generated random sample into a nice scatterplot using for instance the command
