| MRF | R Documentation | 
The functions MRF() and  MRFA() fit a Gaussian Markov Random Fields (MRF) model. They are used by the functions mrf() and  mrfa() respectively to fit a MRF additive term within GAMLSS 
MRF(y, x, precision = NULL, neighbour = NULL, polys = NULL, 
            area = NULL, weights = rep(1, length(y)), sig2e = 1, 
            sig2b =             1, sig2e.fix = FALSE, 
            sig2b.fix = FALSE, penalty = FALSE, 
            delta = c(0.01, 0.01), shift = c(0, 0))
MRFA(y, x, precision = NULL, neighbour = NULL, polys = NULL, 
           area = NULL, weights = rep(1, length(y)), 
           lambda = NULL, df = NULL, start = 10)
| y | response variable | 
| x | a factor containing the areas | 
| precision | the precision matrix if set | 
| neighbour | an object containing the neighbour information for the area if set | 
| polys | the polygon information if set | 
| area | this argument is here to allow more areas than the levels of the factor  | 
| weights | prior weights | 
| sig2e | starting values for the error variance | 
| sig2b | starting values for the random field variance | 
| sig2e.fix | whether sig2e is fixed in the fitting, default equals FALSE | 
| sig2b.fix | whether sig2B is fixed in the fitting, default equals FALSE | 
| penalty | whether quadratic penalty is required to help convergence in for flat likelihoods, this is equivalent of putting a normal prior distribution for the log-sigmas e.g.  | 
| delta | the precision of the prior | 
| shift | the mean of the prior | 
| lambda | smoothing parameter for  | 
| start | starting value for the smoothing parameter  | 
| df | for fixing the degrees of freedom (only in  | 
There are two functions for fitting Markov random fields: i) MRF())  which uses the Q-function (marginal likelihood) for estimating the sig2e and sig2b parameters and ii) MRFA() which estimates the smoothing parameter lambda=sig2e/sig2b using the "alternating" method.
a fitted MRF object
Fernanda De Bastiani, Mikis Stasinopoulos, Robert Rigby and Vlasios Voudouris.
Maintainer: Fernanda <fernandadebastiani@gmail.com>
De Bastiani, F. Rigby, R. A., Stasinopoulos, D. M., Cysneiros, A. H. M. A. and Uribe-Opazo, M. A. (2016) Gaussian Markov random spatial models in GAMLSS. Journal of Applied Statistics, pp 1-19.
Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion), Appl. Statist., 54, part 3, pp 507-554.
Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019) Distributions for modeling location, scale, and shape: Using GAMLSS in R, Chapman and Hall/CRC. An older version can be found in https://www.gamlss.com/.
Rue and Held (2005) Gaussian markov random fields: theory and applications, Chapman & Hall, USA.
Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, https://www.jstatsoft.org/v23/i07/.
Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017) Flexible Regression and Smoothing: Using GAMLSS in R, Chapman and Hall/CRC.
(see also https://www.gamlss.com/).
mrf
library(mgcv)
data(columb)
data(columb.polys)
vizinhos=polys2nb(columb.polys)
precisionC <- nb2prec(vizinhos,x=columb$district)
# MRFA
 m1<-MRFA(columb$crime, columb$district, polys=columb.polys)
m11<-MRFA(columb$crime, columb$district, precision=precisionC)
m12<-MRFA(columb$crime, columb$district,  neighbour=vizinhos)
draw.polys(columb.polys, m12, scheme="heat",swapcolors=TRUE)
## Not run: 
# MRF 
  m2<-MRF(columb$crime, columb$district, polys=columb.polys)
 m21<-MRF(columb$crime, columb$district, precision=precisionC)
 m22<-MRF(columb$crime, columb$district, neighbour=vizinhos)
AIC(m1, m11,m12,m2, m21, m22, k=0)
draw.polys(columb.polys, m12, scheme="heat",swapcolors=TRUE)
# removing one area
columb2 <- columb[-5,]
# creating new precision matrix
precisionC2 <- nb2prec(vizinhos,x=columb$district,area=columb$district)
# MRFA 
# new data but declaring  area
m11<-MRFA(columb2$crime, columb2$district, polys=columb.polys, area=columb$district)
# new data old polys
m112<-MRFA(columb2$crime, columb2$district, polys=columb.polys)
# new data old precision old area
m111<-MRFA(columb2$crime, columb2$district, precision=precisionC,area=columb$district)
# new data old neighbour old area
m121<-MRFA(columb2$crime, columb2$district,  neighbour=vizinhos,area=columb$district)
# new data new precision old area
m113<-MRFA(columb2$crime, columb2$district, precision=precisionC2,area=columb$district)
AIC(m11,m112,m111,m121,m113, k=0)
m11<-MRFA(columb2$crime, columb2$district, polys=columb.polys, area=columb$district)
# new data old polys
m112<-MRFA(columb2$crime, columb2$district, polys=columb.polys)
# new data old precision old area
m111<-MRFA(columb2$crime, columb2$district, precision=precisionC,area=columb$district)
# new data old neighbour old area
m121<-MRFA(columb2$crime, columb2$district,  neighbour=vizinhos,area=columb$district)
# new data new precision old area
m113<-MRFA(columb2$crime, columb2$district, precision=precisionC2,area=columb$district)
AIC(m11,m112,m111,m121,m113, k=0)
draw.polys(columb.polys, fitted(m11))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.