character; target variable name (must be a numeric variable)
lam
numeric; lambda the smoothing parameter
d
numeric; standard depths
vlow
numeric; smallest value of the target variable (smaller values will be replaced)
vhigh
numeric; highest value of the target variable (larger values will be replaced)
show.progress
logical; specifies whether to display the progress bar
Value
Returns a list with four elements:
idcol
site ID column
var.fitted
matrix; are are spline-estimated values of the target variable at observed depths (upper and lower depths are indicated as attributes)
var.std
matrix; are spline-estimated values of the target variable at standard depths
var.1cm
matrix; are spline-estimated values of the target variable using the 1 cm increments
Note
Target variable needs to be a numeric vector measured at least 2 horizons for the spline to be fitted. Profiles with 1 horizon are accepted and processed as per output requirements, but no spline is fitted as such. Only positive numbers for upper and lower depths can be accepted. It is assumed that soil variables collected per horizon refer to block support i.e. they represent averaged values for the whole horizon. This operation can be time-consuming for large data sets.
library(aqp)
library(plyr)
library(sp)
## sample profile from Nigeria:
lon = 3.90; lat = 7.50; id = "ISRIC:NG0017"; FAO1988 = "LXp"
top = c(0, 18, 36, 65, 87, 127)
bottom = c(18, 36, 65, 87, 127, 181)
ORCDRC = c(18.4, 4.4, 3.6, 3.6, 3.2, 1.2)
munsell = c("7.5YR3/2", "7.5YR4/4", "2.5YR5/6", "5YR5/8", "5YR5/4", "10YR7/3")
## prepare a SoilProfileCollection:
prof1 <- join(data.frame(id, top, bottom, ORCDRC, munsell),
data.frame(id, lon, lat, FAO1988), type='inner')
depths(prof1) <- id ~ top + bottom
site(prof1) <- ~ lon + lat + FAO1988
coordinates(prof1) <- ~ lon + lat
proj4string(prof1) <- CRS("+proj=longlat +datum=WGS84")
## fit a spline:
ORCDRC.s <- mpspline(prof1, var.name="ORCDRC")
str(ORCDRC.s)
## Example with multiple soil profiles
## Make some fake, but reasonable profiles:
rand.prof <- ldply(1:20, random_profile, n=c(6, 7, 8), n_prop=1, method='LPP')
## promote to SPC and plot
depths(rand.prof ) <- id ~ top + bottom
plot(rand.prof, color='p1')
## fit MP spline by profile
try( m <- mpspline(rand.prof, 'p1') )
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(GSIF)
GSIF version 0.5-2 (2016-06-25)
URL: http://gsif.r-forge.r-project.org/
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GSIF/mpspline.Rd_%03d_medium.png", width=480, height=480)
> ### Name: mpspline
> ### Title: Fits a mass preserving spline
> ### Aliases: mpspline mpspline,SoilProfileCollection-method
> ### Keywords: methods
>
> ### ** Examples
>
> library(aqp)
This is aqp 1.9.3
> library(plyr)
> library(sp)
> ## sample profile from Nigeria:
> lon = 3.90; lat = 7.50; id = "ISRIC:NG0017"; FAO1988 = "LXp"
> top = c(0, 18, 36, 65, 87, 127)
> bottom = c(18, 36, 65, 87, 127, 181)
> ORCDRC = c(18.4, 4.4, 3.6, 3.6, 3.2, 1.2)
> munsell = c("7.5YR3/2", "7.5YR4/4", "2.5YR5/6", "5YR5/8", "5YR5/4", "10YR7/3")
> ## prepare a SoilProfileCollection:
> prof1 <- join(data.frame(id, top, bottom, ORCDRC, munsell),
+ data.frame(id, lon, lat, FAO1988), type='inner')
Joining by: id
> depths(prof1) <- id ~ top + bottom
Warning message:
converting IDs from factor to character
> site(prof1) <- ~ lon + lat + FAO1988
> coordinates(prof1) <- ~ lon + lat
> proj4string(prof1) <- CRS("+proj=longlat +datum=WGS84")
> ## fit a spline:
> ORCDRC.s <- mpspline(prof1, var.name="ORCDRC")
Fitting mass preserving splines per profile...
| | | 0% | |======================================================================| 100%
> str(ORCDRC.s)
List of 4
$ idcol : chr "ISRIC:NG0017"
$ var.fitted: num [1, 1:6] 17.75 5.12 3.52 3.62 3.16 ...
$ var.std :'data.frame': 1 obs. of 7 variables:
..$ 0-5 cm : num 20.7
..$ 5-15 cm : num 17.4
..$ 15-30 cm : num 7.29
..$ 30-60 cm : num 3.29
..$ 60-100 cm : num 3.61
..$ 100-200 cm: num 1.82
..$ soil depth: num 181
$ var.1cm : num [1:200, 1] 21 20.9 20.7 20.5 20.2 ...
>
> ## Example with multiple soil profiles
> ## Make some fake, but reasonable profiles:
> rand.prof <- ldply(1:20, random_profile, n=c(6, 7, 8), n_prop=1, method='LPP')
> ## promote to SPC and plot
> depths(rand.prof ) <- id ~ top + bottom
> plot(rand.prof, color='p1')
guessing horizon designations are stored in `name`
> ## fit MP spline by profile
> try( m <- mpspline(rand.prof, 'p1') )
Fitting mass preserving splines per profile...
| | | 0% | |==== | 5% | |======= | 10% | |========== | 15% | |============== | 20% | |================== | 25% | |===================== | 30% | |======================== | 35% | |============================ | 40% | |================================ | 45% | |=================================== | 50% | |====================================== | 55% | |========================================== | 60% | |============================================== | 65% | |================================================= | 70% | |==================================================== | 75% | |======================================================== | 80% | |============================================================ | 85% | |=============================================================== | 90% | |================================================================== | 95% | |======================================================================| 100%
>
>
>
>
>
> dev.off()
null device
1
>