ea_spline: Fits a mass preserving spline

Description Usage Arguments Value Note Author(s) References Examples

View source: R/ea_spline.R

Description

This function is specific for soil profile data. A continous spline function is fitted upon information recieved about a target soil property at specified depths intervals or soil horizons. The spline however has the unique property of maintaining the integrity of the observed information i.e. the spline has mass preserving properties.

Usage

1
ea_spline(obj, var.name, lam = 0.1, d = t(c(0,5,15,30,60,100,200)), vlow = 0, vhigh = 1000, show.progress=TRUE)

Arguments

obj

Can be an object of class "data.frame" or "SoilProfileCollection"

var.name

character; target variable name (must be a numeric variable)

lam

numeric; lambda the smoothing parameter

d

numeric; standard depths that are used to extract values from fitted spline i.e harmonising 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; Display the progress bar?

Value

Returns a list with four elements:

harmonised

data frame; are spline-estimated values of the target variable at standard depths

obs.preds

data frame; are observed values together with associated spline predictions for each profile at each depth.

var.1cm

matrix; are spline-estimated values of the target variable using the 1 cm increments

tmse

matrix; True mean square error estimate between observed profiles and associated fitted splines.

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.

Author(s)

Brendan Malone

References

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library(aqp)
library(plyr)
library(sp)


#Fit spline 
data(oneProfile)
class(oneProfile)
sp.fit<- ea_spline(oneProfile, var.name="C.kg.m3.")


#Using a SoilProfileCollection
## 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 spline:
ORCDRC.s <- ea_spline(prof1, var.name="ORCDRC")
str(ORCDRC.s)

ithir documentation built on May 2, 2019, 4:49 p.m.

Related to ea_spline in ithir...