# NOT RUN {
# Summarize Data
summary(ContrivedData)
# Empirical semivariagram for variable y
semivariogram(x=ContrivedData$y, coords = cbind(ContrivedData$s.1, ContrivedData$s.2))
# Initial OLS Model
contrived.ols<-lm(y~x.1+x.2,data=ContrivedData)
# Empirical semivariagram for ols fit
semivariogram(contrived.ols, coords = c("s.1","s.2"), bins=13)
# Set seed
set.seed(1241060320)
M <- 100
#M<-10000
contrived.run <- metropolis.krige(y ~ x.1 + x.2, coords = c("s.1","s.2"),
data = ContrivedData, n.iter = M, range.tol = 0.05)
# Parametric semivariagram
semivariogram(contrived.run, bins=13, terms = c("raw", "residual", "parametric"),
type= c(raw = "p", residual = "p", parametric = "l"), legend = TRUE, col = c("black",
"blue", "red"), pch = c(1,3,NA), lty = c(NA,NA,1))
# Alternatively, the generic function plot can also be applied to krige object
plot(contrived.run)
# Plot semivariance object
plot(semivariance(contrived.run, bins=13))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab