Title: | Spatial Terms in Generalized Additive Models for Location Scale and Shape |
---|---|
Description: | The packages enables fitting Gaussian Markov Random Fields within the Generalized Additive Models for Location Scale and Shape algorithms. |
Authors: | Fernanda De Bastiani [aut, cre, cph] , Mikis Stasinopoulos [aut] , Robert Rigby [aut] |
Maintainer: | Fernanda De Bastiani <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 3.0-3 |
Built: | 2024-10-30 03:14:16 UTC |
Source: | https://github.com/gamlss-dev/gamlss.spatial |
The packages enables fitting Gaussian Markov Random Fields within the Generalized Additive Models for Location Scale and Shape algorithms.
The DESCRIPTION file:
Package: | gamlss.spatial |
Title: | Spatial Terms in Generalized Additive Models for Location Scale and Shape |
Version: | 3.0-3 |
Date: | 2023-11-04 |
Authors@R: | c(person("Fernanda", "De Bastiani", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0001-8532-639X")), person("Mikis", "Stasinopoulos", role = "aut", email = "[email protected]", comment = c(ORCID = "0000-0003-2407-5704")), person("Robert", "Rigby", role = "aut", email = "[email protected]", comment = c(ORCID = "0000-0003-3853-1707")) ) |
Description: | The packages enables fitting Gaussian Markov Random Fields within the Generalized Additive Models for Location Scale and Shape algorithms. |
License: | GPL-2 | GPL-3 |
URL: | https://www.gamlss.com/ |
BugReports: | https://github.com/gamlss-dev/gamlss.spatial/issues |
Depends: | R (>= 2.15.0), gamlss.dist, gamlss (>= 4.2-7), gamlss.add, spam, mgcv |
Imports: | stats, grDevices, graphics, methods |
RoxygenNote: | 5.0.1 |
Repository: | https://gamlss-dev.r-universe.dev |
RemoteUrl: | https://github.com/gamlss-dev/gamlss.spatial |
RemoteRef: | HEAD |
RemoteSha: | 81e65be4aa55a59a025b7caace5b9e9c50bf362a |
Author: | Fernanda De Bastiani [aut, cre, cph] (<https://orcid.org/0000-0001-8532-639X>), Mikis Stasinopoulos [aut] (<https://orcid.org/0000-0003-2407-5704>), Robert Rigby [aut] (<https://orcid.org/0000-0003-3853-1707>) |
Maintainer: | Fernanda De Bastiani <[email protected]> |
Index of help topics:
MRF Markov Random Fields Fitting Functions draw.polys Additional supporting functions for random Markov fields gamlss.gmrf Gaussian Markov Random Field fitting within GAMLSS gamlss.spatial-package Spatial Terms in Generalized Additive Models for Location Scale and Shape
Fernanda De Bastiani [aut, cre, cph] (<https://orcid.org/0000-0001-8532-639X>), Mikis Stasinopoulos [aut] (<https://orcid.org/0000-0003-2407-5704>), Robert Rigby [aut] (<https://orcid.org/0000-0003-3853-1707>)
Maintainer: Fernanda De Bastiani <[email protected]>
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/).
library(mgcv) data(columb) data(columb.polys) m1 <- MRFA(columb$crime, columb$district, polys=columb.polys) draw.polys(columb.polys, m1)
library(mgcv) data(columb) data(columb.polys) m1 <- MRFA(columb$crime, columb$district, polys=columb.polys) draw.polys(columb.polys, m1)
This set of functions were useful in the past to get information and to plot maps but somehow now seem redundant.
draw.polys(polys, object = NULL, scheme = NULL, swapcolors = FALSE, n.col = 100, ...) polys2nb(polys) nb2prec(neighbour,x,area=NULL) polys2polys(object, neighbour.nb) nb2nb(neighbour.nb)
draw.polys(polys, object = NULL, scheme = NULL, swapcolors = FALSE, n.col = 100, ...) polys2nb(polys) nb2prec(neighbour,x,area=NULL) polys2polys(object, neighbour.nb) nb2nb(neighbour.nb)
polys |
an object containing the polygon information for the area |
object |
are either the values to plot in the |
scheme |
scheme of colours to use, it can be |
swapcolors |
to reverse the colours, it just work for |
n.col |
range for the colours |
neighbour.nb |
neighbour information for a shape file for function |
neighbour |
the neighbour information, and if the neighbour is from S4 shape file than use |
x |
the factor defining the areas |
area |
all possible areas involved |
... |
for extra options |
draw.polys()
plots the fitted values of fitted MRF
object.
polys2nb()
gets the neighbour information from the polygons.
nb2prec()
creates the precision matrix from the neighbour information.
polys2polys()
transforms a shape file polygons (S4 object) to the polygons required form for the functions MRF()
and MRFA()
.
nb2nb()
transforms from a shape file neighbour (S4 object) to the neighbour required form for functions MRF()
.
The draw.polys()
produces a plot while the rest of the functions produce required object for fitting or plotting.
Fernanda De Bastiani, Mikis Stasinopoulos, Robert Rigby and Vlasios Voudouris
Maintainer: Fernanda <[email protected]>
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/).
The function gmrf()
can be used to fit Markov Random Field additive terms within GAMLSS.
gamlss.gmrf(x, y, w, xeval = NULL, ...) gmrf(x, precision = NULL, neighbour = NULL, polys = NULL, area = NULL, adj.weight = 1000, df = NULL, lambda = NULL, start = 10, method = c("Q", "A"), control = gmrf.control(...), ...)
gamlss.gmrf(x, y, w, xeval = NULL, ...) gmrf(x, precision = NULL, neighbour = NULL, polys = NULL, area = NULL, adj.weight = 1000, df = NULL, lambda = NULL, start = 10, method = c("Q", "A"), control = gmrf.control(...), ...)
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 |
adj.weight |
a value to adjust the iterative weight if necessary |
df |
degrees of freedom for fitting if required, only for |
lambda |
The smoothing parameter |
start |
starting value for the smoothing parameter |
method |
"Q" for Q-function, or "A" for alternating method |
y |
working response variable |
w |
iterative weights |
xeval |
whether to predict or not |
control |
to be use for some of the argument of |
... |
for extra arguments |
The function gmrf()
is to support the function MRF()
and MRFA()
within GAMLSS.
It is intended to be called within a GAMLSS formula. The function gmrf()
is not intended to be used directly. It is calling the function MRFA()
and MRF()
within the GAMLSS fitting algorithm.
The results using the option method="Q"
or method="A"
should produce identical results.
a fitted gamlss object
Fernanda De Bastiani, Mikis Stasinopoulos, Robert Rigby and Vlasios Voudouris.
Maintainer: Fernanda <[email protected]>
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/).
library(gamlss) library(mgcv) data(columb) data(columb.polys) vizinhos=polys2nb(columb.polys) precisionC <- nb2prec(vizinhos,x=columb$district) # MRFA m1<- gamlss(crime~ gmrf(district, polys=columb.polys, method="Q"), data=columb) m2<- gamlss(crime~ gmrf(district, polys=columb.polys, method="A"), data=columb) AIC(m1,m2, k=0) draw.polys(columb.polys, getSmo(m2), scheme="topo")
library(gamlss) library(mgcv) data(columb) data(columb.polys) vizinhos=polys2nb(columb.polys) precisionC <- nb2prec(vizinhos,x=columb$district) # MRFA m1<- gamlss(crime~ gmrf(district, polys=columb.polys, method="Q"), data=columb) m2<- gamlss(crime~ gmrf(district, polys=columb.polys, method="A"), data=columb) AIC(m1,m2, k=0) draw.polys(columb.polys, getSmo(m2), scheme="topo")
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)
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 <[email protected]>
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/).
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)
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)