RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
StartExample()
################################################################
## ##
## a geostatistical analysis that demonstrates ##
## features of the package `RandomFields' ##
## ##
################################################################
data(soil)
str(soil)
soil <- RFspatialPointsDataFrame(
coords = soil[ , c("x.coord", "y.coord")],
data = soil[ , c("moisture", "NO3.N", "Total.N", "NH4.N", "DOC", "N20N")],
RFparams=list(vdim=6, n=1)
)
data <- soil["moisture"]
if (RFoptions()$internal$examples_red) {
warning("data have been reduced !")
All <- 1:7
data(soil)
soil <- RFspatialPointsDataFrame(
coords = soil[All, c("x.coord", "y.coord")],
data = soil[All, c("moisture", "NO3.N", "Total.N",
"NH4.N", "DOC", "N20N")],
RFparams=list(vdim=6, n=1)
)
data <- soil["moisture"]
}
## plot the data first
colour <- rainbow(100)
plot(data, col=colour)
## fit by eye
gui.model <- RFgui(data)
if (!interactive()) RFgui.model <- RMexp()
## fit by ML
model <- ~1 + RMwhittle(scale=NA, var=NA, nu=NA) + RMnugget(var=NA)
(fit <- RFfit(model, data=data))
plot(fit, method=c("ml", "plain", "sqrt.nr", "sd.inv"),
model = gui.model, col=1:8)
## Kriging ...
x <- seq(min(data@coords[, 1]), max(data@coords[, 1]), l=121)
k <- RFinterpolate(fit, x=x, y=x, data=data)
plot(x=k, col=colour)
plot(x=k, y=data, col=colour)
## what is the probability that at no point of the
## grid given by x and y the moisture is greater than 24 percent?
cs <- RFsimulate(model=fit, x=x, y=x, data=data, n=50)
plot(cs, col=colour)
plot(cs, y=data, col=colour)
Print(mean(apply(as.array(cs) <= 24, 3, all))) ## about 40 percent ...
FinalizeExample()
Run the code above in your browser using DataLab