stvcGLMstack {spStack} | R Documentation |
Bayesian spatially-temporally varying coefficients generalized linear model using predictive stacking
Description
Fits Bayesian spatial-temporal generalized linear model with spatially-temporally varying coefficients on a collection of candidate models constructed based on some candidate values of some model parameters specified by the user and subsequently combines inference by stacking predictive densities. See Pan, Zhang, Bradley, and Banerjee (2024) for more details.
Usage
stvcGLMstack(
formula,
data = parent.frame(),
family,
sp_coords,
time_coords,
cor.fn,
process.type,
priors,
candidate.models,
n.samples,
loopd.controls,
parallel = FALSE,
solver = "ECOS",
verbose = TRUE,
...
)
Arguments
formula |
a symbolic description of the regression model to be fit. Variables in parenthesis are assigned spatially-temporally varying coefficients. See examples. |
data |
an optional data frame containing the variables in the model.
If not found in |
family |
Specifies the distribution of the response as a member of the
exponential family. Supported options are |
sp_coords |
an |
time_coords |
an |
cor.fn |
a quoted keyword that specifies the correlation function used
to model the spatial-temporal dependence structure among the observations.
Supported covariance model key words are: |
process.type |
a quoted keyword specifying the model for the
spatial-temporal process. Supported keywords are |
priors |
(optional) a list with each tag corresponding to a
hyperparameter name and containing hyperprior details. Valid tags include
|
candidate.models |
an object of class |
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. Valid tags include |
parallel |
logical. If |
solver |
(optional) Specifies the name of the solver that will be used
to obtain optimal stacking weights for each candidate model. Default is
|
verbose |
logical. If |
... |
currently no additional argument. |
Value
An object of class stvcGLMstack
, which is a list including the
following tags -
samples
a 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
), spatial effects (z
), and fine scale variationxi
for that model.loopd
a list of length equal to total number of candidate models with each entry containing leave-one-out predictive densities under that particular model.
n.models
number of candidate models that are fit.
candidate.models
a list of length
n_model
rows with each entry containing details of the model parameters.stacking.weights
a numeric vector of length equal to the number of candidate models storing the optimal stacking weights.
run.time
a
proc_time
object with runtime details.solver.status
solver status as returned by the optimization routine.
This object can be further used to recover posterior samples of the scale
parameters in the model, and subsequrently, to make predictions at new
locations or times using the function posteriorPredict()
.
Examples
set.seed(1234)
data("sim_stvcPoisson")
dat <- sim_stvcPoisson[1:100, ]
# create list of candidate models (multivariate)
mod.list2 <- candidateModels(list(phi_s = list(2, 3),
phi_t = list(1, 2),
boundary = c(0.5, 0.75)), "cartesian")
# fit a spatial-temporal varying coefficient model using predictive stacking
mod1 <- stvcGLMstack(y ~ x1 + (x1), data = dat, family = "poisson",
sp_coords = as.matrix(dat[, c("s1", "s2")]),
time_coords = as.matrix(dat[, "t_coords"]),
cor.fn = "gneiting-decay",
process.type = "multivariate",
candidate.models = mod.list2,
loopd.controls = list(method = "CV", CV.K = 10, nMC = 500),
n.samples = 500)