This package implements the methods for Bayesian big data
multivariate spatial regression appearing in Peruzzi and Dunson (2021).
Estimation of all unknowns and predictions are carried out via Markov
chain Monte Carlo within a single function. Refer to the documentation
for the spamtree
function and the examples.
spamtree
Just do install.packages("spamtree")
to install from
CRAN.
A minimal documentation is available for the CRAN package and
accessible from R
via the usual
?spamtree::spamtree
.
spamtree
The methods implemented in the package are described in this article:
M Peruzzi and DB Dunson (2021), https://arxiv.org/abs/2012.00943
High resolution geospatial data are challenging because standard geostatistical models based on Gaussian processes are known to not scale to large data sizes. While progress has been made towards methods that can be computed more efficiently, considerably less attention has been devoted to big data methods that allow the description of complex relationships between several outcomes recorded at high resolutions by different sensors. Our Bayesian multivariate regression models based on spatial multivariate trees (SpamTrees) achieve scalability via conditional independence assumptions on latent random effects following a treed directed acyclic graph. Information-theoretic arguments and considerations on computational efficiency guide the construction of the tree and the related efficient sampling algorithms in imbalanced multivariate settings. In addition to simulated data examples, we illustrate SpamTrees using a large climate data set which combines satellite data with land-based station data.
library(abind)
library(magrittr)
library(tidyverse)
library(spamtree)
set.seed(2021)
<- 25
SS <- SS^2 # total n. locations, including missing ones
n
<- data.frame(Var1=runif(n), Var2=runif(n)) %>%
coords as.matrix()
# generate data
<- 2.3
sigmasq <- 6
phi <- .1
tausq <- c(-1,.5,1)
B
<- sigmasq * exp(-phi * as.matrix(dist(coords)))
CC <- t(chol(CC))
LC <- LC %*% rnorm(n)
w <- length(B)
p <- rnorm(n * p) %>% matrix(ncol=p)
X <- X %*% B + w + tausq^.5 * rnorm(n)
y_full
<- rbinom(n, 1, 0.1)
set_missing
<- data.frame(coords,
simdata y_full = y_full,
w_latent = w) %>%
mutate(y_observed = ifelse(set_missing==1, NA, y_full))
<- simdata$y_observed
y <- mean(y, na.rm=T)
ybar
# MCMC setup
<- 1000
mcmc_keep <- 1000
mcmc_burn <- 2
mcmc_thin
# fit spamtree with defaults
<- spamtree(y - ybar, X, coords,
spamtree_done mcmc = list(keep=mcmc_keep, burn=mcmc_burn, thin=mcmc_thin),
num_threads = 10, verbose=TRUE)
# predictions
<- spamtree_done$yhat_mcmc %>%
y_out abind(along=3) %>% `[`(,1,) %>% add(ybar) %>% apply(1, mean)
<- spamtree_done$w_mcmc %>%
w_out abind(along=3) %>% `[`(,1,) %>% apply(1, mean)
<- spamtree_done$coordsinfo %>%
outdf cbind(data.frame(w_spamtree = w_out,
y_spamtree = y_out)) %>%
left_join(simdata)
# plot predictions
%>%
outdf ggplot(aes(Var1, Var2, color=y_spamtree)) +
geom_point() +
theme_minimal() +
scale_color_viridis_c()
# rmspe
%>%
outdf filter(!complete.cases(.)) %>%
with((y_spamtree - y_full)^2) %>%
mean() %>% sqrt()
# plot latent process
%>%
outdf ggplot(aes(Var1, Var2, color=w_spamtree)) +
geom_point() +
theme_minimal() +
scale_color_viridis_c()
# estimation of regression coefficients
$beta_mcmc[,,1] %>% t() %>%
spamtree_doneas.data.frame() %>%
gather(Coefficient, Sample) %>%
ggplot(aes(Sample)) +
geom_density() +
facet_wrap(~Coefficient, scales="free")