Multivariate Probability Distributions in R
Surajit Ray
Reader, University of Glasgow
Univariate normal with mean 2 and variance 1
Density shape of a bivariate normal
${\mu}={\begin{pmatrix} 1 \\ 2 \end{pmatrix}},\quad { \Sigma }={\begin{pmatrix} 1 & 0.5 \\ 0.5 & 2 \end{pmatrix}}$
${\mu}={\begin{pmatrix} 1 \\ 2 \end{pmatrix}},\quad { \Sigma }={\begin{pmatrix} 1 & 0.5 \\ 0.5 & 2 \end{pmatrix}}$
${\mu}={\begin{pmatrix} -1 \\ -3 \end{pmatrix}},\quad { \Sigma }={\begin{pmatrix} 1 & 0.5 \\ 0.5 & 2 \end{pmatrix}}$
${\mu}={\begin{pmatrix}\phantom{-}1 \\\phantom{-}2 \end{pmatrix}} ,\quad { \Sigma }={\begin{pmatrix}2 & 0 \\ 0 & 2 \end{pmatrix}}$
${\mu}={\begin{pmatrix}\phantom{-}1 \\\phantom{-}2 \end{pmatrix}},\quad { \Sigma }={\begin{pmatrix}1& 0.95 \\0.95 & 1 \end{pmatrix}}$
p
for "probability"q
for "quantile"d
for "density"r
for "random"library(mvtnorm)
rmvnorm(n, mean , sigma)
Need to specify:
n
the number of samplesmean
the mean of the distributionsigma
the variance-covariance matrixGenerate 1000 samples from a 3 dimensional normal with
$$ \mu= \begin{pmatrix} 1 \\ 2 \\ -5 \end{pmatrix} \Sigma={\begin{pmatrix} 1 & 1 & 0 \\ 1 & 2 & 0 \\ 0 & 0 & 5 \end{pmatrix}} $$
mu1 <- c(1, 2, -5)
sigma1 <- matrix(c(1,1,0,
1,2,0,
0,0,5),3,3)
set.seed(34)
rmvnorm(n = 1000, mean = mu1, sigma = sigma1)
Plot of generated samples
Multivariate Probability Distributions in R