R: Random sample from a decomposable Gaussian model

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`, the concentration matrix (and also the covariance matrix) of the multivariate normal. The order of `A` is the number of components of the normal.
`Delta` | a numeric vector of length equal to the number of columns of `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, …, d.

The value in position i 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

`triDec`, `fitDag`

### 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

[Package ggm version 2.3 Index]