# locations
locs <- 1:6
# random effects covariates
W <- cbind(rep(1, 6), 5:10)
# distance matrix with and without tapering
d <- as.matrix(dist(locs))
# distance matrix with and without tapering
tap_dist <- 2
d_tap <- spam::nearest.dist(locs, delta = tap_dist)
# call without tapering
(Sy <- varycoef:::Sigma_y(
x = rep(0.5, 5),
cov_func = function(x) spam::cov.exp(d, x),
outer.W = lapply(1:ncol(W), function(k) W[, k] %o% W[, k])
))
str(Sy)
# call with tapering
(Sy_tap <- varycoef:::Sigma_y(
x = rep(0.5, 5),
cov_func = function(x) spam::cov.exp(d_tap, x),
outer.W = lapply(1:ncol(W), function(k)
spam::as.spam((W[, k] %o% W[, k]) * (d_tap<=tap_dist))
),
taper = spam::cov.wend1(d_tap, c(tap_dist, 1, 0))
))
str(Sy_tap)
# difference between tapered and untapered covariance matrices
Sy-Sy_tap
Run the code above in your browser using DataLab