rnormDag {ggm} | R Documentation |
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 |
a numeric vector of length equal to the number of columns
of |
Details
The value in position of
A
(with ) is
a regression coefficient (with sign changed) in the regression of
variable
on variables
.
The value in position of
Delta
is the residual
variance in the above regression.
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))
.
Author(s)
Giovanni M. Marchetti
References
Cox, D. R. & Wermuth, N. (1996). Multivariate dependencies. London: Chapman & Hall.
See Also
Examples
## 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