Skip to contents

This function generates multivariate normal random numbers.

Usage

SimMVN(n, location, chol_scale)

Arguments

n

Integer. Number of samples to generate.

location

Numeric vector. Mean vector of length k, where k is the number of variables.

chol_scale

Numeric matrix. Cholesky decomposition of the covariance matrix of dimensions k by k.

Value

Matrix containing the simulated multivariate normal random numbers, with dimensions n by k, where n is the number of samples and k is the number of variables.

Details

The SimMVN() function generates multivariate normal random numbers using the Cholesky decomposition method. Given the number of samples n, the mean vector location of length k (where k is the number of variables), and the Cholesky decomposition chol_scale of the covariance matrix of dimensions k by k, the function produces a matrix of multivariate normal random numbers.

The steps involved in generating multivariate normal random numbers are as follows:

  • Determine the number of variables k from the length of the mean vector.

  • Generate random data from a standard multivariate normal distribution, resulting in an n by k matrix of random numbers.

  • Transform the standard normal random data into multivariate normal random data using the Cholesky decomposition chol_scale.

  • Add the mean vector location to the transformed data to obtain the final simulated multivariate normal random numbers.

  • The function returns a matrix of simulated multivariate normal random numbers with dimensions n by k, where n is the number of samples and k is the number of variables. This matrix can be used for various statistical analyses and simulations.

See also

The chol() function in R to obtain the Cholesky decomposition of a covariance matrix.

Other Simulation of Autoregressive Data Functions: CheckARCoef(), CheckVARCoef(), SimARCoef(), SimAR(), SimPD(), SimVARCoef(), SimVARExo(), SimVARZIPExo(), SimVARZIP(), SimVAR(), SimVariance(), YXExo(), YX()

Author

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
n <- 1000L
location <- c(0.5, -0.2, 0.1)
scale <- matrix(
  data = c(1.0, 0.3, 0.3, 0.3, 1.0, 0.2, 0.3, 0.2, 1.0),
  nrow = 3,
  byrow = TRUE
)
chol_scale <- chol(scale)
y <- SimMVN(n = n, location = location, chol_scale = chol_scale)
colMeans(y)
#> [1]  0.4633877 -0.1736762  0.0825133
var(y)
#>           [,1]      [,2]      [,3]
#> [1,] 0.9982658 0.2944345 0.2500963
#> [2,] 0.2944345 0.9484743 0.1941391
#> [3,] 0.2500963 0.1941391 0.9322613