Skip to content

Instantly share code, notes, and snippets.

@mikebirdgeneau
Created September 20, 2016 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebirdgeneau/5b73a0c543a1e37fd5189d78a22f3dfa to your computer and use it in GitHub Desktop.
Save mikebirdgeneau/5b73a0c543a1e37fd5189d78a22f3dfa to your computer and use it in GitHub Desktop.
3D Kriging with Conditional Gaussian Simulation in R
library(gstat)
library(lattice)
# Create Data Points (Random)
n <- 50
data3D <- data.frame(x = runif(n), y = runif(n), z = runif(n), v = rnorm(n))
coordinates(data3D) = ~x+y+z
# Create empty grid to krige
range1D <- seq(from = 0, to = 1, length = 20)
grid3D <- expand.grid(x = range1D, y = range1D, z = range1D)
gridded(grid3D) = ~x+y+z
# Perform CGS with 10 realizations; maxdist & nmax important for speed of calculation.
res3D <- krige(formula = v ~ 1, data3D, grid3D, model = vgm(1, "Exp", .2),nsim=10,maxdist=10,nmax=9)
# Plot Results
levelplot(sim1 ~ x + y | z, as.data.frame(res3D))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment