# rnorm.Q: Sample random normal variables with precision matrix Q. In rwc: Random Walk Covariance Models

## Description

General function to make use of sparse matrix methods to efficiently simulate random multivariate normal random variables with sparse precision matrices.

## Usage

 ```1 2 3``` ```rnorm.Q(Q, mu = rep(0, nrow(Q)), X = Matrix(1, nrow = nrow(Q), ncol = 1), zero.constraint = FALSE, canon = FALSE, diag.adjust = .Machine\$double.eps * 10) ```

## Arguments

 `Q` Precision matrix, defined as a sparse Matrix object. `mu` Mean vector of dimension equal to the dimension of Q. `X` Matrix of vectors which should be orthogonal to the simulated random variable. `zero.constraint` If TRUE, then the simulated random variable is orthogonal to the columns of X. `canon` If TRUE, then draw from the 'canonical form'. `diag.adjust` Numeric value to be added to the diagonal of Q to make it positive definite.

## Details

In the 'canonical form', the variable is drawn from:

v~N(Q^-1 mu, Q^-1)

In the non-canonical form, the variable is drawn from

v~N( mu, Q^-1)

## Value

A vector of the resulting random variable.

Ephraim M. Hanks

## References

Rue and Held 2005. Gaussian Markov Random Fields: theory and applications. Chapman and Hall.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13``` ```ras=raster(nrow=30,ncol=30) extent(ras) <- c(0,30,0,30) values(ras) <- 1 int=ras cov.ras=ras ## simulate "resistance" raster B.int=get.TL(int) Q.int=get.Q(B.int,1) values(cov.ras) <- as.numeric(rnorm.Q(Q.int,zero.constraint=TRUE)) plot(cov.ras) ```

### Example output ```Loading required package: raster