Description Usage Arguments Examples
Draw posterior predictive samples from a spatial Gaussian process model
1 |
x |
Observation of a spatial Gaussian random field, passed as a vector |
sFit |
posterior samples of model parameters; output from bisque::sFit |
coords.krig |
Spatial coordinates at which the field should be interpolated |
coords |
Spatial coordinates at which observations are available |
burn |
number of posterior samples to discard from sFit before sampling |
ncores |
Kriging is done via composition sampling, which may be done in
parallel. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | library(fields)
simulate.field = function(n = 100, range = .3, smoothness = .5, phi = 1){
# Simulates a mean-zero spatial field on the unit square
#
# Parameters:
# n - number of spatial locations
# range, smoothness, phi - parameters for Matern covariance function
coords = matrix(runif(2*n), ncol=2)
Sigma = Matern(d = as.matrix(dist(coords)),
range = range, smoothness = smoothness, phi = phi)
list(coords = coords,
params = list(n=n, range=range, smoothness=smoothness, phi=phi),
x = t(chol(Sigma)) %*% rnorm(n))
}
# simulate data
x = simulate.field()
# configure gibbs sampler
it = 100
# run sampler using default posteriors
post.samples = sFit(x = x$x, coords = x$coords, nSamples = it)
# build kriging grid
cseq = seq(0, 1, length.out = 10)
coords.krig = expand.grid(x = cseq, y = cseq)
# sample from posterior predictive distribution
burn = 75
samples.krig = sKrig(x$x, post.samples, coords.krig = coords.krig, burn = burn)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.