GMRF {glmmAK} | R Documentation |
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).
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)
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 |
Some objects.
A list with the components: description{
and the following attributes: description{
A list with the components: description{
A vector with evaluated values of the (log-)density
Arnošt Komárek arnost.komarek[AT]mff.cuni.cz
Rue, H. and Held, L. (2005). Gaussian Markov Random Fields: Theory and Applications. Boca Raton: Chapman and Hall/CRC.
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)