Learn R Programming

ggm (version 2.2)

rnormDag: Random sample from a decomposable Gaussian model

Description

Generates a sample from a mean centered multivariate normal distribution whose covariance matrix has a given triangular decomposition.

Usage

rnormDag(n, A, Delta)

Arguments

n
an integer > 0, the sample size.
A
a square, upper triangular matrix with ones along the diagonal. It defines, together with Delta, the concentration matrix (and also the covariance matrix) of the multivariate normal. The order of A is the number o
Delta
a numeric vector of length equal to the number of columns of A.

Value

  • a matrix with n rows and nrow(A) columns, a sample from a multivariate normal distribution with mean zero and covariance matrix S = solve(A) %*% diag(Delta) %*% t(solve(A)).

Details

The value in position $(i,j)$ of A (with $i < j$) is a regression coefficient (with sign changed) in the regression of variable $i$ on variables $i+1, \dots, d$.

The value in position $i$ of Delta is the residual variance in the above regression.

References

Cox, D. R. & Wermuth, N. (1996). Multivariate dependencies. London: Chapman & Hall.

See Also

triDec, fitDag

Examples

Run this code
## Generate a sample of 100 observation from a multivariate normal
## The matrix of the path coefficients 
A <- matrix(
c(1, -2, -3,  0, 0,  0,  0,
  0,  1,  0, -4, 0,  0,  0,
  0,  0,  1,  2, 0,  0,  0,
  0,  0,  0,  1, 1, -5,  0,
  0,  0,  0,  0, 1,  0,  3,
  0,  0,  0,  0, 0,  1, -4,
  0,  0,  0,  0, 0,  0,  1), 7, 7, byrow=TRUE)
D <- rep(1, 7)
X <- rnormDag(100, A, D)

## The true covariance matrix
solve(A) %*% diag(D) %*% t(solve(A))

## Triangular decomposition of the sample covariance matrix
triDec(cov(X))$A

Run the code above in your browser using DataLab