Random sample from a decomposable Gaussian model
Generates a sample from a mean centered multivariate normal distribution whose covariance matrix has a given triangular decomposition.
rnormDag(n, A, Delta)
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 |
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, …, d.
The value in position i of Delta
is the residual
variance in the above regression.
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))
.
Giovanni M. Marchetti
Cox, D. R. \& Wermuth, N. (1996). Multivariate dependencies. London: Chapman \& Hall.
## 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
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.