Soil physical and chemical data collected on a field in the
Weissenstaedter Becken, Germany
Usage
data(soil)
Format
This data frame contains the following columns:
x.coord
x coordinates given in cm
y.coord
y coordinates given in cm
nr
number of the samples, which were taken in this order
moisture
moisture content [Kg/Kg * 100%]
NO3.N
nitrate nitrogen [mg/Kg]
Total.N
total nitrogen [mg/Kg]
NH4.N
ammonium nitrogen [mg/Kg]
DOC
dissolved organic carbon [mg/Kg]
N20N
nitrous oxide [mg/Kg dried substance]
Details
For technical reasons some of the data were obtained as differences
of two measurements (which are not available anymore). Therefore,
some of the data have negative values.
Source
The data were collected by Wolfgang Falk,
Soil Physics Group,
University of Bayreuth, Germany.
References
Falk, W. (2000)
Kleinskalige raeumliche Variabilitaet von Lachgas und bodenchemischen
Parameters [Small Scale Spatial Variability of Nitrous Oxide and
Pedo-Chemical Parameters],
Master thesis, University of Bayreuth, Germany.
Examples
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
################################################################
## ##
## 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"]
## plot the data first
colour <- rainbow(100)
plot(data, col=colour)
## fit by eye
gui.model <- RFgui(data)
## 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 ...
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(RandomFields)
Loading required package: sp
Loading required package: RandomFieldsUtils
This is RandomFieldsUtils Version: 0.2.1
This is RandomFields Version: 3.1.16
Attaching package: 'RandomFields'
The following object is masked from 'package:RandomFieldsUtils':
RFoptions
The following objects are masked from 'package:base':
abs, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, exp, expm1,
floor, gamma, lgamma, log, log1p, log2, logb, max, min, round, sin,
sinh, sqrt, tan, tanh, trunc
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/RandomFields/soil.Rd_%03d_medium.png", width=480, height=480)
> ### Name: soil
> ### Title: Soil data of North Bavaria, Germany
> ### Aliases: soil
> ### Keywords: datasets
>
> ### ** Examples
>
>
> RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
> ## RFoptions(seed=NA) to make them all random again
> ## Don't show:
> StartExample()
> ## End(Don't show)
>
>
> ################################################################
> ## ##
> ## a geostatistical analysis that demonstrates ##
> ## features of the package `RandomFields' ##
> ## ##
> ################################################################
>
>
> data(soil)
> str(soil)
'data.frame': 201 obs. of 9 variables:
$ x.coord : num -90 -60 -30 0 30 60 90 -120 -90 -60 ...
$ y.coord : num -150 -150 -150 -150 -150 -150 -150 -120 -120 -120 ...
$ nr : int 1 2 3 4 5 6 7 8 9 10 ...
$ moisture: num 7.23 14.63 12.67 13.73 7.4 ...
$ NO3.N : num 3.77 7.83 11.49 14.48 5.67 ...
$ Total.N : num 34.5 44.2 50.6 52.2 42.2 ...
$ NH4.N : num 4.46 5.14 7.28 6.45 3.45 ...
$ DOC : num 107 135 152 136 135 ...
$ N20N : num 0.000496 0.000404 0.00031 0.000461 0.000518 ...
> 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"]
> ## Don't show:
> 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"]
+ }
Warning message:
data have been reduced !
> ## End(Don't show)
>
> ## plot the data first
> colour <- rainbow(100)
> plot(data, col=colour)
>
>
> ## fit by eye
> gui.model <- RFgui(data)
Warning message:
In RFgui(data) : 'RFgui' can be used only in an interactive mode
> ## Don't show:
> #if (!interactive()) RFgui.model <- RMexp()
> ## End(Don't show)
>
> ## fit by ML
> model <- ~1 + RMwhittle(scale=NA, var=NA, nu=NA) + RMnugget(var=NA)
> (fit <- RFfit(model, data=data))
The modus_operandi='normal' is save, but slow. If you like the MLE running
faster (at the price of being less precise!) choose modus='easygoing' or
even modus='sloppy'.
.........++$
Internal variables:
whittle.var whittle.s whittle.nu nugget.var cst
value 5.169524e+00 3.144890 0.1000000 5.168337e+00 11.7
sd Inf Inf 0.2282568 Inf -
lower 5.169524e-04 1.825742 0.1000000 5.169524e-04 -
upper 1.033905e+02 540.000000 10.0000000 1.033905e+02 -
User's variables:
whittle.var whittle.s whittle.nu nugget.var cst
value 5.169524 3.14489 0.1 5.168337 11.7
sd 9.342639 Inf Inf 1.520771 -
#variab loglikelihood AIC
5.00000 -18.10833 46.21666
Note that the (internal) fitted variable 'whittle.nu' is close to or on the effective lower boundary.
Hence the gradient of the likelihood function might not be zero and none of the
reported 'sd' values might be reliable.
> 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)
Warning message:
In FUN(newX[, i], ...) : range of data is a single value
> 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)
number of simulations reduced
..
New output format of RFsimulate: S4 object of class 'RFsp';
for a bare, but faster array format use 'RFoptions(spConform=FALSE)'.
> plot(cs, col=colour)
> plot(cs, y=data, col=colour)
> Print(mean(apply(as.array(cs) <= 24, 3, all))) ## about 40 percent ...
mean(apply(as.array(cs) <= 24, 3, all)) [1] = 1
>
> ## Don't show:
> FinalizeExample()
> ## End(Don't show)
>
>
>
>
>
> dev.off()
null device
1
>