Learn R Programming

rwc (version 1.12)

rnorm.Q: Sample random normal variables with precision matrix Q.

Description

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

Usage

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)

Value

A vector of the resulting random variable.

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.

Author

Ephraim M. Hanks

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)

References

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

Examples

Run this code
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)

Run the code above in your browser using DataLab