GMRF {glmmAK}R Documentation

Gaussian Markov random fields

Description

Moments, density and random generation for the Gaussian Markov random field with mean equal to 'mean', precision matrix equal to 'Q' (or covariance matrix equal to 'Sigma') and possibly constrained by a linear constraint 'Ax=b'.

Generation of random numbers is performed by Algorithm 2.6 in Rue and Held (2005, pp. 38).

Usage

momentsGMRF(mean=0, Q=1, Sigma, A, b=0)

rGMRF(n, mean=0, Q=1, Sigma, A, b=0)

dGMRF(x, mean=0, Q=1, Sigma, A, b=0, log=FALSE)

dGMRF2(x, mean=0, Q=1, Sigma, A, b=0, log=FALSE)

Arguments

mean vector of mean. If length(mean) is equal to 1, it is recycled and all components have the same mean.
Q precision matrix of the GMRF.
Sigma covariance matrix of the GMRF. Only one of Q and Sigma must be given. If Sigma is supplied, precision is computed from Sigma as Q = Sigma^{-1}.
A optional matrix defining the constraint Ax=b for sampled vectors x.
If not supplied, the GMRF is assumed to be unconstrained.
Currently at most 1 constraint is allowed, that is A must be a vector and b a number.
b vector or the right-hand side of the constraint. If length(b) is equal to 1, it is recycled and all constraint right-hand sides are the same.
n number of observations to be sampled.
x vector or matrix of the points where the density should be evaluated.
log logical; if TRUE, log-density is computed

Value

Some objects.

Value for momentsGMRF

A list with the components: description{

mean
mean of the (constrained) GMRF
Sigma
covariance matrix of the (constrained) GMRF
}

and the following attributes: description{

mean.unconstr
mean of the GMRF before imposing the constraints
Sigma.unconstr
covariance matrix Sigma[u] of the GMRF before imposing the constraints
Q.unconstr.cholesky
Cholesky decomposition of the matrix Q[u]=Sigma[u]^(-1)
nconstraint
number of constraints
A
left-hand side of the constrains
b
right-hand side of the constraints
}

Value for rGMRF

A list with the components: description{

x
vector or matrix with sampled values
log.dens
vector with the values of the log-density evaluated in the sampled values
}

Value for dGMRF, dGMRF2

A vector with evaluated values of the (log-)density

Author(s)

Arnošt Komárek arnost.komarek[AT]mff.cuni.cz

References

Rue, H. and Held, L. (2005). Gaussian Markov Random Fields: Theory and Applications. Boca Raton: Chapman and Hall/CRC.

See Also

dnorm, Mvnorm.

Examples

set.seed(1977)

mu <- c(0, 6, 8)
L <- matrix(1:9, nrow=3)
L[upper.tri(L, diag=FALSE)] <- 0
Sigma <- L %*% t(L)
Q <- chol2inv(chol(Sigma))

A <- rep(1, nrow(Sigma))
b <- 0

##### Unconstrained GMRF
##### ==================
## Moments
momentsGMRF(mean=mu, Sigma=Sigma)
momentsGMRF(mean=mu, Q=Q)

## Random numbers
z <- rGMRF(1000, mean=mu, Sigma=Sigma)
apply(z$x, 2, mean)
var(z$x)

## Random numbers, again
z <- rGMRF(10, mean=mu, Sigma=Sigma)
print(z)

## Values of the log-density
dGMRF(z$x, mean=mu, Sigma=Sigma, log=TRUE)
dGMRF(z$x, mean=mu, Q=Q, log=TRUE)
dGMRF2(z$x, mean=mu, Sigma=Sigma, log=TRUE)
dGMRF2(z$x, mean=mu, Q=Q, log=TRUE)

## Values of the density
dGMRF(z$x, mean=mu, Sigma=Sigma)
dGMRF(z$x, mean=mu, Q=Q)
dGMRF2(z$x, mean=mu, Sigma=Sigma)
dGMRF2(z$x, mean=mu, Q=Q)

##### Constrained GMRF
##### ================
## Moments
momentsGMRF(mean=mu, Sigma=Sigma, A=A, b=b)
momentsGMRF(mean=mu, Q=Q, A=A, b=b)

## Random numbers
z <- rGMRF(1000, mean=mu, Sigma=Sigma, A=A, b=b)
apply(z$x, 2, mean)
var(z$x)

## Random numbers, again
z <- rGMRF(10, mean=mu, Sigma=Sigma, A=A, b=b)
print(z)
A %*% t(z$x)

## Values of the log-density
dGMRF(z$x, mean=mu, Sigma=Sigma, A=A, b=b, log=TRUE)
dGMRF(z$x, mean=mu, Q=Q, A=A, b=b, log=TRUE)
dGMRF2(z$x, mean=mu, Sigma=Sigma, A=A, b=b, log=TRUE)
dGMRF2(z$x, mean=mu, Q=Q, A=A, b=b, log=TRUE)

## Values of the log-density
dGMRF(z$x, mean=mu, Sigma=Sigma, A=A, b=b)
dGMRF(z$x, mean=mu, Q=Q, A=A, b=b)
dGMRF2(z$x, mean=mu, Sigma=Sigma, A=A, b=b)
dGMRF2(z$x, mean=mu, Q=Q, A=A, b=b)

[Package glmmAK version 1.2 Index]