rsglmm: Restricted Spatial Generalized Linear Mixed model

View source: R/rsglmm.R

rsglmmR Documentation

Restricted Spatial Generalized Linear Mixed model

Description

Fit a Restricted Spatial Generalized Linear Mixed model

Usage

rsglmm(data, formula, family,
              E = NULL, n = NULL,
              area = NULL, model = NULL, neigh = NULL,
              proj = "none", nsamp = 1000, burnin = 5000, lag = 1,
              priors = list(prior_prec = list(prec = list(prior = "loggamma", param = c(0.5, 0.0005)))),
              approach = "inla",
              ...)

Arguments

data

a data frame or list containing the variables in the model.

formula

an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted.

family

some allowed families are: 'gaussian', 'poisson' and 'binomial'. The family availability will depend on the approach.

E

known component, in the mean for the Poisson likelihoods defined as E = exp(\eta), where \eta is the linear predictor. Default = 1.

n

a vector containing the number of trials for the binomial likelihood, or the number of required successes for the nbinomial2 likelihood. Default value is set to 1.

area

areal variable name in data.

model

spatial model adopted. Examples: "besag", "besag2" or "r_besag". See INLA::inla.list.models() for other models.

neigh

neighborhood structure. A SpatialPolygonsDataFrame or sf object

proj

"none", "rhz", "hh" or "spock"

nsamp

number of samples. Default = 1000.

burnin

burn-in size (just for hh).

lag

lag parameter (just for hh).

priors

a list containing:

  • prior_prec: a list with:

    • See ?inla.models for the list of hyparameters for each model. Example list(prec = list(prior = "loggamma", param = c(0.5, 0.0005)))

approach

'inla' or 'mcmc'

...

other parameters used in ?INLA::inla or ?ngspatial::sparse.sglmm

Details

The fitted model is given by

Y ~ Poisson(E\theta),

log(\theta) = X\beta + \psi,

\psi ~ ICAR(\tau).

Value

$unrestricted

A list containing

  • $sample: a sample of size nsamp for all parameters in the model

  • $summary_fixed: summary measures for the coefficients

  • $summary_hyperpar: summary measures for hyperparameters

  • $summary_random: summary measures for random quantities

$restricted

A list containing

  • $sample: a sample of size nsamp for all parameters in the model

  • $summary_fixed: summary measures for the coefficients

  • $summary_hyperpar: summary measures for hyperparameters

  • $summary_random: summary measures for random quantities

$out

INLA (unrestricted model) or ngspatial output

$time

time elapsed for fitting the model

Examples

set.seed(123456)

##-- Spatial structure
data("neigh_RJ")

beta <- c(-0.5, -0.2)
tau <- 1

##-- Data ----
family <- "poisson"
data <- rglmm(beta = beta, tau = tau, family = family,
              confounding = "none", neigh = neigh_RJ,
              scale = TRUE)

##-- Models ----
sglm_mod <- rsglmm(data = data, formula = Y ~ X1 + X2,
                   family = family,
                   proj = "none", nsamp = 1000)

sglmm_mod <- rsglmm(data = data, formula = Y ~ X1 + X2,
                    family = family,
                    area = "reg", model = "besag", neigh = neigh_RJ,
                    proj = "none", nsamp = 1000)

rglmm_rhz <- rsglmm(data = data, formula = Y ~ X1 + X2,
                    family = family,
                    area = "reg", model = "r_besag", neigh = neigh_RJ,
                    proj = "rhz", nsamp = 1000)

rglmm_spock <- rsglmm(data = data, formula = Y ~ X1 + X2,
                      family = family,
                      area = "reg", model = "r_besag", neigh = neigh_RJ,
                      proj = "spock", nsamp = 1000)

rglmm_hh <- rsglmm(data = data, formula = Y ~ X1 + X2,
                   family = family,
                   area = "reg", model = "r_besag", neigh = neigh_RJ,
                   approach = "mcmc",
                   proj = "hh", burnin = 5000, nsamp = 1000, lag = 10)

sglm_mod$unrestricted$summary_fixed
sglmm_mod$unrestricted$summary_fixed
rglmm_rhz$unrestricted$summary_fixed
rglmm_rhz$restricted$summary_fixed
rglmm_spock$restricted$summary_fixed
rglmm_hh$restricted$summary_fixed


DouglasMesquita/RASCO documentation built on June 14, 2025, 6:55 p.m.