| svcMsAbund | R Documentation | 
The function svcMsAbund fits multivariate spatially-varying coefficient GLMs with species correlations (i.e., a spatially-explicit abundace-based joint species distribution model). We use  a spatial factor modeling approach. Models are implemented using a Nearest Neighbor Gaussian Process.
svcMsAbund(formula, data, inits, priors, tuning,
           svc.cols = 1, cov.model = 'exponential', NNGP = TRUE,
           n.neighbors = 15, search.type = 'cb', n.factors,
           n.batch, batch.length, accept.rate = 0.43, family = 'Gaussian',
           n.omp.threads = 1, verbose = TRUE, n.report = 100,
           n.burn = round(.10 * n.batch * batch.length), n.thin = 1, n.chains = 1,
           ...)
| formula | a symbolic description of the model to be fit for the model using R's model syntax. Only right-hand side of formula is specified. See example below. Random intercepts and slopes are allowed using lme4 syntax (Bates et al. 2015). | 
| data | a list containing data necessary for model fitting.
Valid tags are  | 
| inits | a list with each tag corresponding to a parameter name.
Valid tags are  | 
| priors | a list with each tag corresponding to a parameter name.
Valid tags are  | 
| tuning | a list with each tag corresponding to a parameter name, whose value defines
the initial tuning variance of the adaptive sampler for  | 
| svc.cols | a vector indicating the variables whose effects will be
estimated as spatially-varying coefficients.  | 
| cov.model | a quoted keyword that specifies the covariance
function used to model the spatial dependence structure among the
observations.  Supported covariance model key words are:
 | 
| NNGP | if  | 
| n.neighbors | number of neighbors used in the NNGP. Only used if
 | 
| search.type | a quoted keyword that specifies the type of nearest
neighbor search algorithm. Supported method key words are:  | 
| n.factors | the number of factors to use in the spatial factor model approach for each spatially-varying coefficient. Typically, the number of factors is set to be small (e.g., 4-5) relative to the total number of species in the community, which will lead to substantial decreases in computation time. However, the value can be anywhere between 1 and the number of species in the modeled community. | 
| n.batch | the number of MCMC batches in each chain to run for the adaptive MCMC sampler. See Roberts and Rosenthal (2009) for details. | 
| batch.length | the length of each MCMC batch to run for the adaptive MCMC sampler. See Roberts and Rosenthal (2009) for details. | 
| accept.rate | target acceptance rate for adaptive MCMC. Default is 0.43. See Roberts and Rosenthal (2009) for details. | 
| family | the distribution to use for abundance. Currently, spatially-varying
coefficient models are available for  | 
| n.omp.threads | a positive integer indicating
the number of threads to use for SMP parallel processing. The package must
be compiled for OpenMP support. For most Intel-based machines, we
recommend setting  | 
| verbose | if  | 
| n.report | the interval to report Metropolis sampler acceptance and MCMC progress. Note this is specified in terms of batches and not overall samples for spatial models. | 
| n.burn | the number of samples out of the total  | 
| n.thin | the thinning interval for collection of MCMC samples. The
thinning occurs after the  | 
| n.chains | the number of chains to run in sequence. | 
| ... | currently no additional arguments | 
An object of class svcMsAbund that is a list comprised of:
| beta.comm.samples | a  | 
| tau.sq.beta.samples | a  | 
| beta.samples | a  | 
| tau.sq.samples | a  | 
| theta.samples | a  | 
| lambda.samples | a  | 
| y.rep.samples | a three or four-dimensional array of posterior samples for the fitted (replicate) values for each species with dimensions corresponding to MCMC sample, species, site, and replicate. | 
| mu.samples | a three or four-dimensional array of posterior samples for the expected abundance values for each species with dimensions corresponding to MCMC samples, species, site, and replicate. | 
| w.samples | a four-dimensional array of posterior samples for the latent spatial random effects for each spatial factor within each spatially-varying coefficient. Dimensions correspond to MCMC sample, factor, site, and spatially-varying coefficient. | 
| sigma.sq.mu.samples | a  | 
| beta.star.samples | a  | 
| like.samples | a three-dimensional array of posterior samples for the likelihood value associated with each site and species. Used for calculating WAIC. | 
| rhat | a list of Gelman-Rubin diagnostic values for some of the model parameters. | 
| ESS | a list of effective sample sizes for some of the model parameters. | 
| run.time | MCMC sampler execution time reported using  | 
The return object will include additional objects used for subsequent prediction and/or model fit evaluation.
Jeffrey W. Doser doserjef@msu.edu, 
Andrew O. Finley finleya@msu.edu
Datta, A., S. Banerjee, A.O. Finley, and A.E. Gelfand. (2016) Hierarchical Nearest-Neighbor Gaussian process models for large geostatistical datasets. Journal of the American Statistical Association, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.2015.1044091")}.
Finley, A.O., A. Datta, B.D. Cook, D.C. Morton, H.E. Andersen, and S. Banerjee. (2019) Efficient algorithms for Bayesian Nearest Neighbor Gaussian Processes. Journal of Computational and Graphical Statistics, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10618600.2018.1537924")}.
Roberts, G.O. and Rosenthal J.S. (2009) Examples of adaptive MCMC. Journal of Computational and Graphical Statistics, 18(2):349-367.
Bates, Douglas, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v067.i01")}.
Christensen, W. F., and Amemiya, Y. (2002). Latent variable analysis of multivariate spatial data. Journal of the American Statistical Association, 97(457), 302-317.
set.seed(332)
J.x <- 10
J.y <- 10
J <- J.x * J.y
n.rep <- rep(1, J)
n.sp <- 6
# Community-level covariate effects
beta.mean <- c(0, 0.25, 0.6)
p.abund <- length(beta.mean)
tau.sq.beta <- c(0.2, 1.2, 0.4)
# Random effects
mu.RE <- list()
# Draw species-level effects from community means.
beta <- matrix(NA, nrow = n.sp, ncol = p.abund)
for (i in 1:p.abund) {
  beta[, i] <- rnorm(n.sp, beta.mean[i], sqrt(tau.sq.beta[i]))
}
sp <- TRUE
svc.cols <- c(1, 2)
n.factors <- 2
q.p.svc <- length(svc.cols) * n.factors
factor.model <- TRUE
phi <- runif(q.p.svc, 3/1, 3 / .4)
tau.sq <- runif(n.sp, 0.1, 5)
cov.model <- 'exponential'
family <- 'Gaussian'
dat <- simMsAbund(J.x = J.x, J.y = J.y, n.rep = n.rep, n.sp = n.sp, beta = beta,
                  mu.RE = mu.RE, sp = sp, tau.sq = tau.sq, family = family,
                  factor.model = factor.model, phi = phi,
                  cov.model = cov.model, n.factors = n.factors,
                  svc.cols = svc.cols)
y <- dat$y
X <- dat$X
coords <- dat$coords
covs <- data.frame(abund.cov.1 = X[, 2],
                   abund.cov.2 = X[, 3])
data.list <- list(y = y, covs = covs, coords = coords)
prior.list <- list(beta.comm.normal = list(mean = 0, var = 100),
                   tau.sq.ig = list(a = 2, b = 2),
		   phi.unif = list(a = 3 / 1, b = 3 / .1),
                   tau.sq.beta.ig = list(a = .1, b = .1))
inits.list <- list(beta.comm = 0,
                   beta = 0,
                   tau.sq = 1,
                   tau.sq.beta = 1,
                   phi = 3 / 0.5)
tuning.list <- list(phi = 0.5)
n.batch <- 5
batch.length <- 25
n.burn <- 0
n.thin <- 1
n.chains <- 1
out <- svcMsAbund(formula = ~ abund.cov.1 + abund.cov.2,
                  data = data.list,
                  n.batch = n.batch,
                  inits = inits.list,
                  priors = prior.list,
                  tuning = tuning.list,
                  NNGP = TRUE,
                  svc.cols = c(1, 2),
                  family = 'Gaussian',
                  cov.model = 'exponential',
                  n.neighbors = 5,
                  n.factors = n.factors,
                  batch.length = batch.length,
                  n.omp.threads = 1,
                  verbose = TRUE,
                  n.report = 20,
                  n.burn = n.burn,
                  n.thin = n.thin,
                  n.chains = n.chains)
summary(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.