
Bayesian spatially varying coefficients generalized linear model using predictive stacking
Source:R/svcGLMstack.R
svcGLMstack.RdFits Bayesian generalized linear models with spatially varying coefficients on a collection of candidate models constructed from candidate values of the spatial process parameters and the boundary adjustment parameter supplied by the user, and combines inference by stacking predictive densities. See Pan, Zhang, Bradley, and Banerjee (2025) for more details.
Usage
svcGLMstack(
formula,
data = parent.frame(),
family,
coords,
cor.fn,
process.type,
priors,
candidate.models,
n.samples,
loopd.controls,
parallel = FALSE,
solver = NULL,
verbose = TRUE,
...
)Arguments
- formula
a symbolic description of the regression model to be fit. Variables in parenthesis are assigned spatially varying coefficients. See examples.
- data
an optional data frame containing the variables in the model. If not found in
data, the variables are taken fromenvironment(formula), typically the environment from whichsvcGLMstackis called.- family
Specifies the distribution of the response as a member of the exponential family. Supported options are
'poisson','binomial'and'binary'.- coords
an \(n \times 2\) matrix of the observation coordinates in \(\mathbb{R}^2\) (e.g., easting and northing).
- cor.fn
a quoted keyword that specifies the correlation function used to model the spatial dependence structure among the observations. Supported covariance model key words are:
'exponential'and'matern'.- process.type
a quoted keyword specifying the model for the spatial processes:
'independent','independent.shared'or'multivariate'. SeesvcGLMexact().- priors
(optional) a list with each tag corresponding to a hyperparameter name and containing hyperprior details. Valid tags include
V.beta,nu.beta,nu.z,sigmaSq.xiandIW.scale. SeesvcGLMexact(). If not supplied, uses defaults.- candidate.models
an object of class
candidateModelscontaining a list of candidate models for stacking, each with tagsphi,nu(only ifcor.fn = 'matern'), vectors of length \(r\) ifprocess.type = 'independent'(uselist()entries incandidateModels()) and scalars otherwise, andboundary, a scalar. SeecandidateModels()for details.- n.samples
number of samples to be drawn from the posterior distribution.
- loopd.controls
a list with details on how leave-one-out predictive densities (LOO-PD) are to be calculated, with tags
method('exact'or'CV'),CV.K,nMCandCV.update, as instvcGLMstack(). If sample size is more than 100, then the default is'CV'withCV.K = 10.- parallel
logical. If
parallel=FALSE, the parallelization plan, if set up by the user, is ignored. Ifparallel=TRUE, the function inherits the parallelization plan that is set by the user via the functionfuture::plan()only. Depending on the parallel backend available, users may choose their own plan. More details are available at https://cran.R-project.org/package=future.- solver
(optional) Specifies the name of the solver that will be used to obtain optimal stacking weights for each candidate model. Default order is
c("CLARABEL", "ECOS", "SCS"). Users can use other solvers supported by the CVXR-package package.- verbose
logical. If
TRUE, prints model-specific optimal stacking weights.- ...
currently no additional argument.
Value
An object of class svcGLMstack, which is a list including the
following tags -
samplesa list of length equal to total number of candidate models with each entry corresponding to a list of length 3, containing posterior samples of fixed effects (
beta), the spatially varying coefficients (z), and fine scale variationxifor that model.loopda list of length equal to total number of candidate models with each entry containing leave-one-out predictive densities under that particular model.
n.modelsnumber of candidate models that are fit.
model.paramsa list with one element per candidate model, each a named list of its parameters:
phi,nu(NAfor the exponential correlation function) andboundary.stacking.summarya matrix with one row per candidate model, containing its parameters and its optimal stacking weight, for display.
stacking.weightsa numeric vector of length equal to the number of candidate models storing the optimal stacking weights.
run.timea
proc_timeobject with runtime details.diagnosticsa list of diagnostics, as in
stvcGLMstack(): elementnumerical(columnsmin.pivot,min.corandmax.cor, seesvcGLMexact()) and elementsolver. Ifverbose = TRUE, a "Diagnostics" section is printed if there is an issue.
This object can be further used to recover posterior samples of the scale
parameters in the model with recoverGLMscale(), to make predictions at new
locations with posteriorPredict(), and to sample from the stacked
posterior with stackedSampler().
Details
Candidate models that share the process parameters \((\phi, \nu)\) are fitted together: the spatial correlation matrices and all the pre-processing for the leave-one-out predictive densities are computed once and shared across their boundary values, and the groups of such candidates are the units of parallel work.
References
Pan S, Zhang L, Bradley JR, Banerjee S (2025). "Bayesian Inference for Spatial-temporal Non-Gaussian Data Using Predictive Stacking." Bayesian Analysis, In Press. doi:10.1214/25-BA1582 .
Author
Soumyakanti Pan span18@ucla.edu,
Sudipto Banerjee sudipto@ucla.edu
Examples
set.seed(1234)
data(simSpatial)
dat <- simSpatial[1:100, ]
# processes sharing (phi, nu): scalar candidates
mod.list <- candidateModels(list(phi = c(4, 8), nu = c(1.5),
boundary = c(0.5, 0.75)), "cartesian")
mod1 <- svcGLMstack(y_svc_pois ~ x1 + x2 + (x1), data = dat,
family = "poisson",
coords = as.matrix(dat[, c("s1", "s2")]),
cor.fn = "matern", process.type = "independent.shared",
candidate.models = mod.list,
loopd.controls = list(method = "CV", CV.K = 10, nMC = 500),
n.samples = 500)
#>
#> STACKING WEIGHTS:
#>
#> | phi | nu | boundary | weight |
#> +---------+-----+-----+----------+--------+
#> | Model 1 | 4| 1.5| 0.50| 0.000 |
#> | Model 2 | 8| 1.5| 0.50| 0.346 |
#> | Model 3 | 4| 1.5| 0.75| 0.000 |
#> | Model 4 | 8| 1.5| 0.75| 0.654 |
#> +---------+-----+-----+----------+--------+
#>
post_samps <- stackedSampler(mod1)