set.seed(0)################################################################
## ##
## a geostatistical analysis that demonstrates ##
## features of the package `RandomFields' ##
## ##
################################################################
\dontrun{
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)
)
## plot the data first
colour <- rainbow(100)
plot(soil["moisture"], col=colour)
x <- seq(min(soil@coords[, 1]), max(soil@coords[, 1]), l=121)
## fit by eye
RFgui.model <- RFgui(soil["moisture"])
\dontshow{if (!interactive()) RFgui.model <- RMexp()}
## fit by ML
model <- ~1 + RMplus(RMwhittle(scale=NA, var=NA, nu=NA), RMnugget(var=NA))
fit <- RFfit(model, data=soil["moisture"])
plot(fit, fit.method=c("ml", "plain", "sqrt.nr", "sd.inv"),
model = RFgui.model, col=1:8)
## Kriging ...
k <- RFinterpolate(fit["ml"], x=x, y=x, grid=TRUE, data=soil["moisture"])
plot(x=k, col=colour)
plot(x=k, y=soil["moisture"], 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["ml"], x=x, y=x, data=soil["moisture"], n=50)
plot(cs, col=colour)
plot(cs, y=soil["moisture"], col=colour)
Print(mean(apply(as.matrix(cs@data) <= 24, 2, all))) ## about 40 percent
##...
}
Run the code above in your browser using DataLab