Package 'gamlss.spatial'

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

Help Index


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.

Details

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

Author(s)

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]>

References

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

Examples

library(mgcv)
data(columb)
data(columb.polys)
m1 <- MRFA(columb$crime, columb$district, polys=columb.polys)
draw.polys(columb.polys, m1)

Additional supporting functions for random Markov fields

Description

This set of functions were useful in the past to get information and to plot maps but somehow now seem redundant.

Usage

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)

Arguments

polys

an object containing the polygon information for the area

object

are either the values to plot in the draw.polys() function or a polygons information for a shape file for function polys2polys

scheme

scheme of colours to use, it can be "heat", "rainbow", "terrain", "topo", "cm" or any colour

swapcolors

to reverse the colours, it just work for "heat", "rainbow", "terrain", "topo", "cm" options

n.col

range for the colours

neighbour.nb

neighbour information for a shape file for function nb2nb

neighbour

the neighbour information, and if the neighbour is from S4 shape file than use nb2nb to transfer it to the appropriate neighbour for MRF(), MRFA(), mrf() and mrfa().

x

the factor defining the areas

area

all possible areas involved

...

for extra options

Details

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

Value

The draw.polys() produces a plot while the rest of the functions produce required object for fitting or plotting.

Author(s)

Fernanda De Bastiani, Mikis Stasinopoulos, Robert Rigby and Vlasios Voudouris

Maintainer: Fernanda <[email protected]>

References

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

See Also

MRF, MRFA


Gaussian Markov Random Field fitting within GAMLSS

Description

The function gmrf() can be used to fit Markov Random Field additive terms within GAMLSS.

Usage

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

Arguments

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 x, see example below

adj.weight

a value to adjust the iterative weight if necessary

df

degrees of freedom for fitting if required, only for method="A"

lambda

The smoothing parameter lambda if known, only for method="A"

start

starting value for the smoothing parameter lambda

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

...

for extra arguments

Details

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.

Value

a fitted gamlss object

Author(s)

Fernanda De Bastiani, Mikis Stasinopoulos, Robert Rigby and Vlasios Voudouris.

Maintainer: Fernanda <[email protected]>

References

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

See Also

MRF, MRFA

Examples

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

Markov Random Fields Fitting Functions

Description

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

Usage

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)

Arguments

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 x, see example below.

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. logsig2e-N(shift, 1/delta)

delta

the precision of the prior

shift

the mean of the prior

lambda

smoothing parameter for MRFA function

start

starting value for the smoothing parameter lambda for MRFA function

df

for fixing the degrees of freedom (only in MRFA())

Details

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.

Value

a fitted MRF object

Author(s)

Fernanda De Bastiani, Mikis Stasinopoulos, Robert Rigby and Vlasios Voudouris.

Maintainer: Fernanda <[email protected]>

References

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

See Also

mrf

Examples

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)