Title: | Miscellaneous Functions for Environmental Analyses |
---|---|
Description: | Small toolbox for data analyses in environmental chemistry and ecotoxicology. Provides, for example, calibration() to calculate calibration curves and corresponding limits of detection (LODs) and limits of quantification (LOQs) according to German DIN 32645 (2008). texture() makes it easy to estimate soil particle size distributions from hydrometer measurements (ASTM D422-63, 2007). |
Authors: | Zacharias Steinmetz [aut, cre] , Julius Albert [ctb] , Kilian Kenngott [ctb] |
Maintainer: | Zacharias Steinmetz <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.7.0 |
Built: | 2024-11-16 06:07:19 UTC |
Source: | https://github.com/zsteinmetz/envalysis |
This wrapper function categorizes water drop penetration times (WDPT) in seconds according to the scale proposed by Bisdom et al. (1993).
bisdom(x, ...)
bisdom(x, ...)
x |
a numeric vector containing WDPT measurement data [s]. |
... |
arguments passed to |
Zacharias Steinmetz
Bisdom, E., Dekker, L., & Schoute, J. (1993). Water Repellency of Sieve Fractions from Sandy Soils and Relationships with Organic Material and Soil Structure. Geoderma 56, 105-118. doi:10.1016/0016-7061(93)90103-R
findInterval()
for the generic function.
bisdom(c(2,6,20,NA,3,385))
bisdom(c(2,6,20,NA,3,385))
Defines a 'calibration
' object for the calculation of concentrations
from measurement signals including estimations for the limit of detection
(LOD) and limit of quantification (LOQ) in accordance with DIN 32645 (2008).
calibration( formula, data = NULL, blanks = NULL, weights = NULL, model = "lm", check_assumptions = TRUE, ... ) ## S3 method for class 'calibration' print(x, ...) ## S3 method for class 'calibration' summary(object, ...) ## S3 method for class 'calibration' plot(x, interval = "conf", level = 0.95, ...) ## S3 method for class 'calibration' as.list(x, which = c("coef", "adj.r.squared", "lod", "loq", "blanks"), ...) lod(x, ...) ## Default S3 method: lod(x, ...) ## S3 method for class 'calibration' lod(x, blanks = NULL, alpha = 0.01, level = 0.05, ...) loq(x, ...) ## Default S3 method: loq(x, ...) ## S3 method for class 'calibration' loq(x, blanks = NULL, alpha = 0.01, k = 3, level = 0.05, maxiter = 10, ...) ## S3 method for class 'calibration' predict(object, newdata = NULL, interval = "conf", ...) inv_predict(x, ...) ## Default S3 method: inv_predict(x, ...) ## S3 method for class 'calibration' inv_predict(x, y, below_lod = NULL, method = "analytic", ...)
calibration( formula, data = NULL, blanks = NULL, weights = NULL, model = "lm", check_assumptions = TRUE, ... ) ## S3 method for class 'calibration' print(x, ...) ## S3 method for class 'calibration' summary(object, ...) ## S3 method for class 'calibration' plot(x, interval = "conf", level = 0.95, ...) ## S3 method for class 'calibration' as.list(x, which = c("coef", "adj.r.squared", "lod", "loq", "blanks"), ...) lod(x, ...) ## Default S3 method: lod(x, ...) ## S3 method for class 'calibration' lod(x, blanks = NULL, alpha = 0.01, level = 0.05, ...) loq(x, ...) ## Default S3 method: loq(x, ...) ## S3 method for class 'calibration' loq(x, blanks = NULL, alpha = 0.01, k = 3, level = 0.05, maxiter = 10, ...) ## S3 method for class 'calibration' predict(object, newdata = NULL, interval = "conf", ...) inv_predict(x, ...) ## Default S3 method: inv_predict(x, ...) ## S3 method for class 'calibration' inv_predict(x, y, below_lod = NULL, method = "analytic", ...)
formula |
model formula providing the recorded signal intensities with
respect to the nominal/specified analyte concentrations in the form of
|
data |
an optional data frame containing the variables in the model. |
blanks |
a vector of numeric blank values overriding those automatically retrieved from calibration data. |
weights |
an optional character string containing one or more model
variables, for example, in the form of " |
model |
model class to be used for fitting; currently,
|
check_assumptions |
automatically check for normality and
homoscedasticity of model residuals using |
... |
further arguments passed to submethods; for
instance, the respective model environment such as |
x , object
|
an object of class ' |
interval |
type of interval plotted (can be abbreviated); see
|
level |
tolerance/confidence level; see |
which |
character vector indicating the parameters to export; defaults
to |
alpha |
numeric; error tolerance for the detection limit (critical value). |
k |
numeric; relative uncertainty for the limit of quantification
( |
maxiter |
a positive integer specifying the maximum number of iterations to calculate the LOQ. |
newdata |
a data frame in which to look for variables with which to
predict. If |
y |
numeric; the value to inverse predict. |
below_lod |
value to be assigned if inverse prediction is below LOD;
defaults to |
method |
character indicating the method used for inverse prediction;
defaults to |
The LOD is defined as the lowest quantity of a substance that can be
distinguished from the absence of that substance (blank value) within a given
confidence level (alpha
). The LOQ is defined as the lowest quantity of
a substance that can be quantified/distinguished from another sample given
with respect to a defined confidence level (k
).
If the data
supplied to calibration
contain more than one blank
value, namely measurements with a nominal/specified concentration of or close
to zero, the LOD and LOQ are calculated from the deviation of the blank
samples. This method is called "blank method" according to DIN 32645 (2008)
and supposed to be more accurate than the so-called "calibration method"
which will be used for the estimation of LOD and LOQ when data
does
not contain zero concentration measurements.
calibration
returns an object of class
'calibration
'.
print()
calls the function parameters together with the respective LOD
and LOQ.
summary()
may be used to retrieve the summary of the underlying model.
plot()
plots the respective calibration curve together with the
measurement values.
as.list()
returns a named list.
lod()
and loq()
return a named vector with the LOD and LOQ
together with lower and upper confidence limits.
predict()
returns a data.frame
of predictions.
inv_predict()
predicts/calculates analyte concentrations from signal
intensities.
Zacharias Steinmetz
Almeida, A.M.D., Castel-Branco, M.M., & Falcao, A.C. (2002). Linear regression for calibration lines revisited: weighting schemes for bioanalytical methods. Journal of Chromatography B, 774(2), 215-222. doi:10.1016/S1570-0232(02)00244-1.
Currie, L.A. (1999). Nomenclature in evaluation of analytical methods including detection and quantification capabilities: (IUPAC Recommendations 1995). Analytica Chimica Acta 391, 105-126.
DIN 32645 (2008). Chemical analysis - Decision limit, detection limit and determination limit under repeatability conditions - Terms, methods, evaluation. Technical standard. Deutsches Institut für Normung, Berlin.
Massart, D.L., Vandeginste, B.G., Buydens, L.M.C., Lewi, P.J., & Smeyers-Verbeke, J. (1997). Handbook of chemometrics and qualimetrics: Part A. Elsevier Science Inc.
invest()
for alternative inverse prediction methods;
Other calibration:
din32645
,
icp
,
matrix_effect()
,
neitzel2003
,
phenolics
,
weight_select()
data(din32645) din <- calibration(Area ~ Conc, data = din32645) print(din) summary(din) plot(din) as.list(din) lod(din) loq(din) predict(din) inv_predict(din, 5000)
data(din32645) din <- calibration(Area ~ Conc, data = din32645) print(din) summary(din) plot(din) as.list(din) lod(din) loq(din) predict(din) inv_predict(din, 5000)
Data obtained with a 152H hydrometer in accordance with ASTM D422-63 (2007).
A data frame containing 7 rows and 4 columns with information on:
the measurement time [min]
the temperature of the soil suspension [°C]
the hydrometer reading at the bottom of the meniscus
a blank value obtained in 5 g/L sodium hexametaphosphate solution (composite correction)
ASTM International
ASTM D422-63 (2007). Standard Test Method for Particle-Size Analysis of Soils. Technical standard. ASTM International, West Conshohocken, PA. Available from https://www.astm.org/standards/d422.
Other texture:
texture()
Sample data for the calibration of carbon in water.
A data frame containing 20 rows and 2 columns with information on:
nominal concentration [mg/L]
measurement signal
Deutsches Institut für Normung
DIN 32645 (2008). Chemical analysis - Decision limit, detection limit and determination limit under repeatability conditions - Terms, methods, evaluation. Technical standard. Deutsches Institut für Normung, Berlin.
Other calibration:
calibration()
,
icp
,
matrix_effect()
,
neitzel2003
,
phenolics
,
weight_select()
Sample data of the calibration of silver ions in four-fold replication using inductively coupled plasma atomic emission spectroscopy (ICP-AES).
A data frame containing 16 rows and 6 columns with information on:
sample name
element name
nominal concentration
concentration units
signal intensity [cps]
number of the respective replicate
Zacharias Steinmetz
Other calibration:
calibration()
,
din32645
,
matrix_effect()
,
neitzel2003
,
phenolics
,
weight_select()
Calculate the matrix effect by comparing the slope of a solvent-based calibration curve with one or more matrix-matched calibration. The matrix effect is expressed as signal suppression/enhancement ratio.
matrix_effect(object, ...) ## S3 method for class 'calibration' matrix_effect(object, ...)
matrix_effect(object, ...) ## S3 method for class 'calibration' matrix_effect(object, ...)
object |
an object of class ' |
... |
additional objects of the same type obtained from matrix-matched calibration data. |
Matrix effects or signal suppression/enhancement ratios should be evaluated during analytical method development to avoid over- or underestimation of sample concentrations. In addition, signal suppression/enhancement ratios may help to justify the validity of a regular solvent calibration as opposed to matrix-matched calibrations. This may be the case if matrix effects or signal suppression/enhancement ratios are close to measurement repeatability.
The magnitude of a matrix effect is estimated by subtracting the slope of a matrix-matched calibration from that of the solvent-based calibration. The difference is divided by the slope of the solvent-based calibration.
Julius Albert, Zacharias Steinmetz
Other calibration:
calibration()
,
din32645
,
icp
,
neitzel2003
,
phenolics
,
weight_select()
data(din32645) din <- calibration(Area ~ Conc, data = din32645) m32645 <- din32645 m32645$Area <- din32645$Area * 1.5 matrix <- calibration(Area ~ Conc, data = m32645) matrix_effect(din, matrix)
data(din32645) din <- calibration(Area ~ Conc, data = din32645) m32645 <- din32645 m32645$Area <- din32645$Area * 1.5 matrix <- calibration(Area ~ Conc, data = m32645) matrix_effect(din, matrix)
Artificial sample data for the verification of quantification limits.
A data frame containing 20 rows and 2 columns with information on:
nominal concentration
measurement signal
Volkmar Neitzel
Neitzel, V. (2003). Kalibrierung bei Analysenverfahren - Bestimmungsgrenze ist nicht gleich Bestimmungsgrenze. CLB Chemie in Labor und Biotechnik, 54(7), 242-246
Other calibration:
calibration()
,
din32645
,
icp
,
matrix_effect()
,
phenolics
,
weight_select()
The sample data is stored in a list consisting of two
data.frame
s: a sequence table (seq
) and a sample
table (samples
).
The sequence table contains gas-chromatography/mass spectrometry measurement data of two phenolic compounds, these are tyrosol and vanillin. Besides the samples, standard mixtures and extraction blanks were acquired in three separate analysis batches. Each measurement resulted in an integrated peak area.
The sample table describes the samples' origin from a 29-day degradation experiment, in which the phenolic compounds were either degraded in the dark by the native soil microbial community or photooxidized under UV irradiation. The samples were processed in threefold replication. Their weight [g], the volume [mL] of extract solution, and the dilution factor were recorded.
A list containing two data.frame
s.
seq
is a data frame with 160 rows and 6 columns with information on:
name of the phenolic compound
sample type
number of the extraction batch
sample name
integrated peak area
specified/nominal concentration [mg/L] of standards
samples
is a data frame with 42 rows and 9 columns with information
on:
sample name; same as in seq
day of the incubation experiment
lighting conditions of the sample (dark/UV)
if the sample was sterilized prior incubation
treatment name (Biogradation/Photooxidation)
replicate number
sample weight [g]
extract volume [mL]
dilution factor
Zacharias Steinmetz
Steinmetz, Z., Kurtz, M.P., Zubrod, J.P., Meyer, A.H., Elsner, M., & Schaumann, G.E. (2019) Biodegradation and photooxidation of phenolic compounds in soil—A compound-specific stable isotope approach. Chemosphere 230, 210-218. DOI: doi:10.1016/j.chemosphere.2019.05.030.
Other calibration:
calibration()
,
din32645
,
icp
,
matrix_effect()
,
neitzel2003
,
weight_select()
This function computes the root mean square error (RMSE) between a vector of
observed values x
and simulated values y
. rel = FALSE
returns the absolute RMSE, rel = TRUE
the relative one. If
na.rm
is TRUE
, missing values are omitted before the
computation proceeds.
rmse(x, y, rel = F, na.rm = T)
rmse(x, y, rel = F, na.rm = T)
x |
a numeric vector containing observed values. |
y |
a numeric vector containing simulated values. |
rel |
logical. If |
na.rm |
logical. Should missing values be removed? |
Zacharias Steinmetz
rmse(c(0.12,0.59,NA), c(0.15,0.63,1.2))
rmse(c(0.12,0.59,NA), c(0.15,0.63,1.2))
These wrapper functions compute the standard error (SE) or the confidence
interval (CI) of the values in x
. If na.rm
is TRUE
,
missing values are removed before the computation proceeds.
se(x, na.rm = FALSE) CI(x, level = 0.95, na.rm = FALSE)
se(x, na.rm = FALSE) CI(x, level = 0.95, na.rm = FALSE)
x |
a numeric vector or an R object which is coercible to one by
|
na.rm |
logical. Should missing values be removed? |
level |
the confidence level required. |
Zacharias Steinmetz
sd()
for the standard deviation.
se(1:5) CI(1:5)
se(1:5) CI(1:5)
This function reports the significant figures of a given mean
together
with its respective error
term (for instance confidence interval or
standard deviation).
signifig(x, error, data, style = "pm", na.digit = 2, ...)
signifig(x, error, data, style = "pm", na.digit = 2, ...)
x |
a numeric vector or data frame object containing the averaged values. |
error |
a numeric vector or data frame object containing the respective error terms. |
data |
a data frame containing the specified columns. If empty, |
style |
a string specifying the output style to be used. The default
style |
na.digit |
an integer controlling to which significant digit the mean value should be rounded if the error is zero or no error data was provided. |
... |
arguments passed to |
Zacharias Steinmetz
Taylor, J.R. (1997). Error analysis: the study of uncertainties in physical measurements. University Science Books, Sausalito, CA.
signifig(c(0.28, 5, -31.6, 2.6, 2, NA, 27.1), c(0.688, 0.8, 11.6, 9.6, NA, 1.6, 0))
signifig(c(0.28, 5, -31.6, 2.6, 2, NA, 27.1), c(0.688, 0.8, 11.6, 9.6, NA, 1.6, 0))
This function returns the concentration of a substance sorbed to a surface
boundary after an equilibrium has established at constant temperature given
the concentration(s) x
of the dissolved substance.
sorption(x, par, type = "freundlich")
sorption(x, par, type = "freundlich")
x |
a numeric vector containing the concentration(s) of the dissolved substance. |
par |
a numeric vector specifying the function parameters, see examples for details and correct order. |
type |
a character string indicating the type of sorption isotherm to be used:
|
Zacharias Steinmetz
Atkins, P.W. (2001). Physical chemistry, Oxford University Press, Oxford.
sorption(1:5, par = c(Kd = 2.5), type = "linear") sorption(1:5, par = c(K = 4, n = 0.6), type = "freundlich") sorption(1:5, par = c(KL = 2, qmax = 10), type = "langmuir") sorption(1:5, par = c(K = 50, qmax = 10, Csat = 10), type = "BET") sorption(1:5, par = c(A = 30, B = 0.8), type = "redlich")
sorption(1:5, par = c(Kd = 2.5), type = "linear") sorption(1:5, par = c(K = 4, n = 0.6), type = "freundlich") sorption(1:5, par = c(KL = 2, qmax = 10), type = "langmuir") sorption(1:5, par = c(K = 50, qmax = 10, Csat = 10), type = "BET") sorption(1:5, par = c(A = 30, B = 0.8), type = "redlich")
Calculates the particle size distribution and both DIN and USDA texture classes from a series of hydrometer readings in accordance with ASTM D422-63 (2007).
texture(reading, ...) ## S3 method for class 'formula' texture(formula, data = NULL, ...) ## Default S3 method: texture( reading, blank, time, temp, conc = 50, Gs = 2.65, hydrometer = "auto", model = "auto", plot = F, ... ) ## S3 method for class 'texture' print(x, ...) ## S3 method for class 'texture' plot(x, ...) as_tridata(x, ...) ## Default S3 method: as_tridata(x, ...) ## S3 method for class 'texture' as_tridata(x, which = NULL, ...)
texture(reading, ...) ## S3 method for class 'formula' texture(formula, data = NULL, ...) ## Default S3 method: texture( reading, blank, time, temp, conc = 50, Gs = 2.65, hydrometer = "auto", model = "auto", plot = F, ... ) ## S3 method for class 'texture' print(x, ...) ## S3 method for class 'texture' plot(x, ...) as_tridata(x, ...) ## Default S3 method: as_tridata(x, ...) ## S3 method for class 'texture' as_tridata(x, which = NULL, ...)
reading |
a numeric vector of data values providing the hydrometer readings at the bottom of the meniscus. |
... |
further arguments to be passed to |
formula |
an object of class ' |
data |
a data frame containing the variables in |
blank |
a numeric vector containing the blank readings taken in 5 g/L sodium hexametaphosphate solution (composite correction). |
time |
a numeric vector containing the time passed since the beginning of the measurement in minutes. |
temp |
an integer vector containing the measured temperature. |
conc |
the concentration of the soil solution, default is 50 g/L as proposed in the ASTM guideline. |
Gs |
specific gravity of the suspension. |
hydrometer |
a character string specifying the hydrometer used; accepted
values are |
model |
string is passed to |
plot |
logical; if |
x |
an object of class ' |
which |
character value indicating the soil texture classification
system to export; accepts |
texture
returns an object of class
'texture
'.
The functions print
() and plot
() are available to retrieve the
soil texture classes and the particle size distribution, respectively.
An object of class 'texture
' is a list containing the following
components:
meta
Measurement meta data
distribution
data frame providing the particle size distribution
model
information on the fitted drm
model
din
Main DIN texture classes
usda
Main USDA texture classes
as_tridata
converts 'texture
' to data.frames of a specific
structure require for soiltexture-package
.
Zacharias Steinmetz
ASTM D422-63 (2007). Standard Test Method for Particle-Size Analysis of Soils. Technical standard. ASTM International, West Conshohocken, PA. Available from https://www.astm.org/standards/d422.
Other texture:
clayloam
data(clayloam) texture(reading ~ blank + time + temperature, data = clayloam)
data(clayloam) texture(reading ~ blank + time + temperature, data = clayloam)
Themes set the general aspect of the plot such as the color of the
background, grid lines, the size and color of fonts. This particular theme is
based on the classic dark-on-light ggplot2 theme_bw
and has been used for scientific publications.
theme_publish(base_size = 12, base_family = "", base_linewidth = 0.25, ...)
theme_publish(base_size = 12, base_family = "", base_linewidth = 0.25, ...)
base_size |
base font size |
base_family |
base font family |
base_linewidth |
base line width for ticks and axes |
... |
further arguments to be passed to |
Zacharias Steinmetz
library(ggplot2) p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap( ~ am) p p + theme_publish()
library(ggplot2) p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap( ~ am) p p + theme_publish()
Selecting optimum model weights by comparing sum relative errors, this is
relerr()
, of weighted calibration()
models as
suggested by Almeida et al. (2002).
weight_select(x, weights, ...) ## S3 method for class 'calibration' weight_select(x, weights = NULL, ...) relerr(x) ## S3 method for class 'calibration' relerr(x)
weight_select(x, weights, ...) ## S3 method for class 'calibration' weight_select(x, weights = NULL, ...) relerr(x) ## S3 method for class 'calibration' relerr(x)
x |
an object of class ' |
weights |
a list of weights to be added to the default weights to be
checked. These are |
... |
further arguments passed to |
If calibration data is not homoscedastic, a weighted least squares linear
calibration model may be applied to counteract the influence of high
concentrations on the regression model. This, in turn, typically improves the
accuracy at the lower end of the calibration curve (Almeida et al., 2002).
weight_select
uses sum relative errors (relerr
) to
find the best weight as suggested by Almeida et al. (2002). Predefined
weights include 1/concentration^0.5
, 1/concentration^1
,
1/concentration^2
, 1/signal^0.5
, 1/signal^1
, and
1/signal^2
(see calibration()
for details).
weight_select()
produces a matrix with differently weighted
'calibration
' models ordered by sum relative errors.
relerr()
compares the nominal concentrations with those predicted by
the calibration
model.
Julius Albert, Kilian Kenngott, Zacharias Steinmetz
Almeida, A.M.D., Castel-Branco, M.M., & Falcao, A.C. (2002). Linear regression for calibration lines revisited: weighting schemes for bioanalytical methods. Journal of Chromatography B, 774(2), 215-222. doi:10.1016/S1570-0232(02)00244-1.
Other calibration:
calibration()
,
din32645
,
icp
,
matrix_effect()
,
neitzel2003
,
phenolics
data(din32645) din <- calibration(Area ~ Conc, data = din32645) weight_select(din) relerr(din)
data(din32645) din <- calibration(Area ~ Conc, data = din32645) weight_select(din) relerr(din)