GMRF                 package:glmmAK                 R Documentation

_G_a_u_s_s_i_a_n _M_a_r_k_o_v _r_a_n_d_o_m _f_i_e_l_d_s

_D_e_s_c_r_i_p_t_i_o_n:

     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).

_U_s_a_g_e:

     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)

_A_r_g_u_m_e_n_t_s:

    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

_V_a_l_u_e:

     Some objects.

_V_a_l_u_e _f_o_r _m_o_m_e_n_t_s_G_M_R_F:

     A list with the components:

     _m_e_a_n mean of the (constrained) GMRF

     _S_i_g_m_a covariance matrix of the (constrained) GMRF

     and the following attributes:

     _m_e_a_n._u_n_c_o_n_s_t_r mean of the GMRF before imposing the constraints

     _S_i_g_m_a._u_n_c_o_n_s_t_r covariance matrix Sigma[u] of the GMRF before
          imposing the constraints

     _Q._u_n_c_o_n_s_t_r._c_h_o_l_e_s_k_y Cholesky decomposition of the matrix
          Q[u]=Sigma[u]^(-1)

     _n_c_o_n_s_t_r_a_i_n_t number of constraints

     _A left-hand side of the constrains

     _b right-hand side of the constraints    

_V_a_l_u_e _f_o_r _r_G_M_R_F:

     A list with the components:

     _x vector or matrix with sampled values

     _l_o_g._d_e_n_s vector with the values of the log-density evaluated in
          the sampled values

_V_a_l_u_e _f_o_r _d_G_M_R_F, _d_G_M_R_F_2:

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

_A_u_t_h_o_r(_s):

     Arno&#353t Kom&#225rek arnost.komarek[AT]mff.cuni.cz

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'dnorm', 'Mvnorm'.

_E_x_a_m_p_l_e_s:

     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)

