Title: | Mass-Preserving Spline Functions for Soil Data |
---|---|
Description: | A low-dependency implementation of GSIF::mpspline() <https://r-forge.r-project.org/scm/viewvc.php/pkg/R/mpspline.R?view=markup&revision=240&root=gsif>, which applies a mass-preserving spline to soil attributes. Splining soil data is a safe way to make continuous down-profile estimates of attributes measured over discrete, often discontinuous depth intervals. |
Authors: | Lauren O'Brien [aut, cre] |
Maintainer: | Lauren O'Brien <[email protected]> |
License: | GPL |
Version: | 0.1.8 |
Built: | 2025-03-02 05:04:16 UTC |
Source: | https://github.com/obrl-soil/mpspline2 |
This function implements the mass-preserving spline method of Bishop et al (1999) (doi:10.1016/S0016-7061(99)00003-8) for interpolating between measured soil attributes down a soil profile, across multiple sites' worth of data.
mpspline( obj = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
mpspline( obj = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
obj |
data.frame or matrix. Column 1 must contain site identifiers. Columns 2 and 3 must contain upper and lower sample depths, respectively. Subsequent columns will contain measured values for those depths. |
var_name |
length-1 character or length-1 integer denoting the column in
|
lam |
number; smoothing parameter for spline. Defaults to 0.1. |
d |
sequential integer vector; denotes the output depth ranges in cm.
Defaults to |
vlow |
numeric; constrains the minimum predicted value to a realistic number. Defaults to 0. |
vhigh |
numeric; constrains the maximum predicted value to a realistic number. Defaults to 1000. |
A nested list of data for each input site. List elements are: Site
ID, vector of predicted values over input intervals, vector of predicted
values for each cm down the profile to max(d)
, vector of predicted
values over d
(output) intervals, and root mean squared error.
dat <- data.frame("SID" = c( 1, 1, 1, 1, 2, 2, 2, 2), "UD" = c( 0, 20, 40, 60, 0, 15, 45, 80), "LD" = c(10, 30, 50, 70, 5, 30, 60, 100), "VAL" = c( 6, 4, 3, 10, 0.1, 0.9, 2.5, 6), stringsAsFactors = FALSE) m1 <- mpspline(obj = dat, var_name = 'VAL')
dat <- data.frame("SID" = c( 1, 1, 1, 1, 2, 2, 2, 2), "UD" = c( 0, 20, 40, 60, 0, 15, 45, 80), "LD" = c(10, 30, 50, 70, 5, 30, 60, 100), "VAL" = c( 6, 4, 3, 10, 0.1, 0.9, 2.5, 6), stringsAsFactors = FALSE) m1 <- mpspline(obj = dat, var_name = 'VAL')
This function implements the mass-preserving spline method of Bishop et
al (1999) (doi:10.1016/S0016-7061(99)00003-8) for interpolating between
measured soil attributes down a soil profile, across multiple sites' worth of
data. It returns a more compact output object than
mpspline()
.
mpspline_compact( obj = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
mpspline_compact( obj = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
obj |
data.frame or matrix. Column 1 must contain site identifiers. Columns 2 and 3 must contain upper and lower sample depths, respectively. Subsequent columns will contain measured values for those depths. |
var_name |
length-1 character or length-1 integer denoting the column in
|
lam |
number; smoothing parameter for spline. Defaults to 0.1. |
d |
sequential integer vector; denotes the output depth ranges in cm.
Defaults to |
vlow |
numeric; constrains the minimum predicted value to a realistic number. Defaults to 0. |
vhigh |
numeric; constrains the maximum predicted value to a realistic number. Defaults to 1000. |
A four-item list containing a matrix of predicted values over the input depth ranges, a matrix of predicted values over the output depth ranges, a matrix of 1cm predictions, and a matrix of RMSE and IQR-scaled RMSE values. Site identifiers are in rownames attributes.
dat <- data.frame("SID" = c( 1, 1, 1, 1, 2, 2, 2, 2), "UD" = c( 0, 20, 40, 60, 0, 15, 45, 80), "LD" = c(10, 30, 50, 70, 5, 30, 60, 100), "VAL" = c( 6, 4, 3, 10, 0.1, 0.9, 2.5, 6), stringsAsFactors = FALSE) mpspline_compact(obj = dat, var_name = 'VAL')
dat <- data.frame("SID" = c( 1, 1, 1, 1, 2, 2, 2, 2), "UD" = c( 0, 20, 40, 60, 0, 15, 45, 80), "LD" = c(10, 30, 50, 70, 5, 30, 60, 100), "VAL" = c( 6, 4, 3, 10, 0.1, 0.9, 2.5, 6), stringsAsFactors = FALSE) mpspline_compact(obj = dat, var_name = 'VAL')
This function implements the mass-preserving spline method of Bishop et al (1999) (doi:10.1016/S0016-7061(99)00003-8) for interpolating between measured soil attributes down a single soil profile.
mpspline_one( site = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
mpspline_one( site = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
site |
data frame containing data for a single soil profile. Column 1 must contain site identifiers. Columns 2 and 3 must contain upper and lower sample depths, respectively, measured in centimeters. Subsequent columns will contain measured values for those depths. |
var_name |
length-1 character or length-1 integer denoting the column in
|
lam |
number; smoothing parameter for spline. Defaults to 0.1. |
d |
sequential integer vector; denotes the output depth ranges in cm.
Defaults to |
vlow |
numeric; constrains the minimum predicted value to a realistic number. Defaults to 0. |
vhigh |
numeric; constrains the maximum predicted value to a realistic number. Defaults to 1000. |
A list with the following elements: Site ID, vector of predicted
values over input intervals, vector of predicted values for each cm down
the profile to max(d)
, vector of predicted values over d
(output) intervals, and root mean squared error.
dat <- data.frame("SID" = c( 1, 1, 1, 1), "UD" = c( 0, 20, 40, 60), "LD" = c(10, 30, 50, 70), "VAL" = c( 6, 4, 3, 10), stringsAsFactors = FALSE) mpspline_one(site = dat, var_name = 'VAL')
dat <- data.frame("SID" = c( 1, 1, 1, 1), "UD" = c( 0, 20, 40, 60), "LD" = c(10, 30, 50, 70), "VAL" = c( 6, 4, 3, 10), stringsAsFactors = FALSE) mpspline_one(site = dat, var_name = 'VAL')
This function implements the mass-preserving spline method of Bishop et al (1999) (doi:10.1016/S0016-7061(99)00003-8) for interpolating between measured soil attributes down a soil profile, across multiple sites' worth of data. It returns an output object with tidy data formatting.
mpspline_tidy( obj = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
mpspline_tidy( obj = NULL, var_name = NULL, lam = 0.1, d = c(0, 5, 15, 30, 60, 100, 200), vlow = 0, vhigh = 1000 )
obj |
data.frame or matrix. Column 1 must contain site identifiers. Columns 2 and 3 must contain upper and lower sample depths, respectively, and be measured in centimeters. Subsequent columns will contain measured values for those depths. |
var_name |
length-1 character or length-1 integer denoting the column in
|
lam |
number; smoothing parameter for spline. Defaults to 0.1. |
d |
sequential integer vector; denotes the output depth ranges in cm.
Defaults to |
vlow |
numeric; constrains the minimum predicted value to a realistic number. Defaults to 0. |
vhigh |
numeric; constrains the maximum predicted value to a realistic number. Defaults to 1000. |
A four-item list containing data frames of predicted values over the input depth ranges, the output depth ranges, 1cm-increment predictions, and RMSE and IQR-scaled RMSE values.
dat <- data.frame("SID" = c( 1, 1, 1, 1, 2, 2, 2, 2), "UD" = c( 0, 20, 40, 60, 0, 15, 45, 80), "LD" = c(10, 30, 50, 70, 5, 30, 60, 100), "VAL" = c( 6, 4, 3, 10, 0.1, 0.9, 2.5, 6), stringsAsFactors = FALSE) mpspline_tidy(obj = dat, var_name = 'VAL')
dat <- data.frame("SID" = c( 1, 1, 1, 1, 2, 2, 2, 2), "UD" = c( 0, 20, 40, 60, 0, 15, 45, 80), "LD" = c(10, 30, 50, 70, 5, 30, 60, 100), "VAL" = c( 6, 4, 3, 10, 0.1, 0.9, 2.5, 6), stringsAsFactors = FALSE) mpspline_tidy(obj = dat, var_name = 'VAL')