25 Workshop Activities
In this lab, you will learn how to:
- simulate correlated random variables using linear transformations,
- generate multivariate normal samples,
- use Cholesky decomposition to induce dependence,
- understand the basic idea of copulas,
- simulate dependent variables with non-normal marginals.
Exercise 2: Linear Transformations of Random Vectors
Suppose \(\mathbf{X} \sim N(\mu, \Sigma)\), and define
\[ \mathbf{Y} = A\mathbf{X} + \mathbf{b}, \]
where
\[ A = \begin{pmatrix} 1 & 0 \\ -1 & 2 \end{pmatrix}, \qquad \mathbf{b} = \begin{pmatrix} 0 \\ 1 \end{pmatrix}. \]
- Generate \(\mathbf{X}\) from Exercise 1, then apply the transformation above.
- Plot the transformed \(Y_1\) against \(Y_2\). Compare it with the plot of original \(X_1\) against \(X_2\). How has the location and the shape of the cloud changed?
- Compute the sample mean of \(\mathbf{Y}\). Is it close to \(A\mu + b\)?
Exercise 3: Simulating from a Multivariate Normal Distribution
You may also simulate multivariate normal data directly using mvrnorm() from the MASS package.
Generate 5000 observations from \[ \mu = \begin{pmatrix} 1 \\ 2 \end{pmatrix}, \qquad \Sigma = \begin{pmatrix} 4 & 1 \\ 1 & 1 \end{pmatrix}. \]
Compare the sample mean with \(\mu\).
Compare the sample covariance matrix with \(\Sigma\).
Why do the sample quantities differ slightly from the theoretical values?
Exercise 5: Gaussian Copula (Normal-Exponential)
simulate:
- \(X \sim N(0,1)\)
- \(Y \sim \text{Exp}(1)\)
using a Gaussian copula with dependence parameter \(\rho = 0.7\). To do this, first generate a latent bivariate normal vector \[ (Z_1, Z_2)^\top \sim N(\mathbf 0, \Sigma), \] where \[ \mathbf 0 = \begin{pmatrix} 0\\ 0 \end{pmatrix}, \qquad \Sigma = \begin{pmatrix} 1 & 0.7\\ 0.7 & 1 \end{pmatrix}. \] Then transform \[ U_1 = \Phi(Z_1), \qquad U_2 = \Phi(Z_2), \] and finally set \[ X = \Phi^{-1}(U_1), \qquad Y = F^{-1}_{\text{Exp}(1)}(U_2). \]
Plot histogram for \(X\) and \(Y\). Briefly explain the shape.
Plot \(X\) against \(Y\). Briefly explain the dependence structure.
How is copula-based model different from a multivariate normal model?
Exercise 6: Gaussian Copula (Gamma-Beta)
- Simulate dependent variables with:
- \(X \sim \text{Gamma}(2,1)\)
- \(Y \sim \text{Beta}(2,5)\) using Gaussian copula with dependence parameter \(\rho = 0.6\).
- Plot histogram for \(X\) and \(Y\). Briefly explain the shape.
- Plot \(X\) against \(Y\). Briefly explain the dependence structure.
Exercise 7: Gaussian Copula (Normal-Exponential-Gamma)
- Simulate three dependent variables:
- \(X_1 \sim N(0,1)\)
- \(X_2 \sim \text{Exp}(1)\)
- \(X_3 \sim \text{Gamma}(3,2)\)
- using a Gaussian copula with correlation matrix \[ \Sigma = \begin{pmatrix} 1 & 0.6 & 0.3 \\ 0.6 & 1 & 0.5 \\ 0.3 & 0.5 & 1 \end{pmatrix}. \]
- Plot marginal histograms and pairwise scatterplots.
- Check the sample correlation matrix.