
Predict at new locations using a fitted spBPS model
predict.spBPS.RdGenerates posterior predictive samples at new spatial locations using a
fitted spBPS object. Memory usage is controlled via
pred_batch_size
Arguments
- object
Object of class
"spBPS"returned byspBPS().- newdata
List with elements
X(u x p covariate matrix) andcoords(u x d coordinate matrix).- draws
Integer. Number of posterior predictive draws. Default 200.
- pred_batch_size
Integer. Number of prediction sites processed per batch. Default 200. Smaller values use less RAM; larger values may be faster.
- n_cores
Integer. Number of OMP threads. Default 1.
- return_summary
Logical. If
FALSE(default) return full draw arrays. IfTRUEreturn summary statistics.- probs
Numeric vector of length 2. Quantile probabilities for credible intervals when
return_summary = TRUE. Defaultc(0.025, 0.975).- ...
Currently unused.
Value
When return_summary = FALSE, a list with arrays Wu,
Yu, MY of dimension u x q x R.
When return_summary = TRUE, a list with u x q matrices
mu_Yu, sd_Yu, q_lo, q_hi, mu_Wu.
Examples
# \donttest{
n <- 1000
p <- 2
q <- 1
Y <- matrix(rnorm(n * q), ncol = q)
X <- matrix(rnorm(n * p), ncol = p)
coords <- matrix(runif(n * 2), ncol = 2)
data <- list(Y = Y, X = X)
priors <- list(mu_B = matrix(0, nrow = p, ncol = q),
V_r = diag(10, p),
Psi = diag(1, q),
nu = 3)
hyperpar <- list(alpha = 0.5, phi = 1)
res <- spBPS(data, priors, coords, hyperpar, subset_size = 200)
#>
#> ====================================================
#> Welcome to spBPS Bayesian Engine
#> ====================================================
#>
#> Partitioning data into K = 5 subsets ...
#>
#> Computing local stacking weights over J = 1 models ...
#> Local weights computed in 0.1 s.
#>
#> Computing global stacking weights over K = 5 partitions ...
#> Global weights computed in 0.0 s.
#>
#> ====================================================
#> spBPS pipeline completed successfully!
#> ====================================================
#> Fitting: 0.1 s
#> Combination: 0.0 s
#> TOTAL: 0.1 s
#>
u <- 500
p <- 2
q <- 1
X_u <- matrix(rnorm(u * p), ncol = p)
crd_u <- matrix(runif(u * 2), ncol = 2)
# Predictive sampling
pred <- predict(res, newdata=list(X=X_u, coords=crd_u),
draws=200L, pred_batch_size=500L)
#> [predict.spBPS] u = 500 draws = 200 cores = 1
#> Completed in 0.3 s.
# Summary statistics only (memory-efficient for large u)
pred_sum <- predict(res, newdata=list(X=X_u, coords=crd_u),
draws=500L, return_summary=TRUE,
probs=c(0.025, 0.975))
#> [predict.spBPS] u = 500 draws = 500 cores = 1
#> Completed in 0.5 s.
# }