Title: | R Functions to Model CDOM Spectra |
---|---|
Description: | Wrapper functions to model and extract various quantitative information from absorption spectra of chromophoric dissolved organic matter (CDOM). |
Authors: | Philippe Massicotte [aut, cre] |
Maintainer: | Philippe Massicotte <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.0.9000 |
Built: | 2024-10-27 04:04:34 UTC |
Source: | https://github.com/pmassicotte/cdom |
Fit an exponential model to CDOM data.
cdom_exponential(wl, absorbance, wl0 = 350, startwl, endwl)
cdom_exponential(wl, absorbance, wl0 = 350, startwl, endwl)
wl |
The wavelength vector. |
absorbance |
The absorbance vector. |
wl0 |
The reference wavelength (ex.: 350). |
startwl |
The starting wavelength (ex.: 240). |
endwl |
The ending wavelength (ex.: 600). |
A list containing:
A data frame with values of fitted parameters.
R2 of the nls model.
A data frame with fitted (predicted) values of the model.
The function will return NULL
if the model did not converged.
# Fit an exponential model using the reference wavelength 350 between 190 and 900 nm. data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) plot(spectra$wavelength, spectra$spc1) lines(spectra$wavelength, fit$data$.fitted, col = "red")
# Fit an exponential model using the reference wavelength 350 between 190 and 900 nm. data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) plot(spectra$wavelength, spectra$spc1) lines(spectra$wavelength, fit$data$.fitted, col = "red")
Calculate the slope ratio (SR) from an absorption spectra.
cdom_slope_ratio(wl, absorbance)
cdom_slope_ratio(wl, absorbance)
wl |
The wavelength vector. |
absorbance |
The absorbance vector. |
Calculate the slope ratio (SR) as defined by Helms et al. (2008).
The value of the slope ratio.
http://www.aslo.org/lo/toc/vol_53/issue_3/0955.html
data("spectra") cdom_slope_ratio(spectra$wavelength, spectra$spc1)
data("spectra") cdom_slope_ratio(spectra$wavelength, spectra$spc1)
Calculate the spectral curve of CDOM spectra has proposed by Loiselle et al. 2009.
cdom_spectral_curve(wl, absorbance, interval = 21, r2threshold = 0.8)
cdom_spectral_curve(wl, absorbance, interval = 21, r2threshold = 0.8)
wl |
The wavelength vector. |
absorbance |
The absorbance vector. |
interval |
The interval used to claculate each slope (default = 21 nm). |
r2threshold |
The r2 threshold that determines if a slope is "valide". The default value is 0.8 meaning that the determination coefficient of the regression between log-transformed data and wavelength should be >= 0.8. |
A dataframe containing the centered wavelength, the calculated slope and the determination coefficient of the linear regression used to claculate the slope.
http://doi.wiley.com/10.4319/lo.2009.54.2.0590
data(spectra) res <- cdom_spectral_curve(spectra$wavelength, spectra$spc2) plot(res$wl, res$s, type = "l")
data(spectra) res <- cdom_spectral_curve(spectra$wavelength, spectra$spc2) plot(res$wl, res$s, type = "l")
Extract Model Coefficients from a CDOM exponential fit
## S3 method for class 'exponential_fit' coef(object, ...)
## S3 method for class 'exponential_fit' coef(object, ...)
object |
An object returned by |
... |
other arguments. |
A numerical vector with estimated coefficients.
data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) coef(fit)
data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) coef(fit)
Plot a Fitted CDOM Exponential Curve
## S3 method for class 'exponential_fit' plot(x, ...)
## S3 method for class 'exponential_fit' plot(x, ...)
x |
An object returned by |
... |
other arguments. |
A ggplot2 object.
library(ggplot2) data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) p <- plot(fit) p p + ggtitle("My super fit")
library(ggplot2) data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) p <- plot(fit) p p + ggtitle("My super fit")
Predict method for CDOM exponential fit
## S3 method for class 'exponential_fit' predict(object, ...)
## S3 method for class 'exponential_fit' predict(object, ...)
object |
An object returned by |
... |
other arguments. |
A numerical vector with predicted values.
data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) predict(fit)
data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) predict(fit)
Simple absorption spectra used to test package's functions.
data(spectra)
data(spectra)
A data frame with 711 rows and 26 variables
wavelength. Wavelengths used for measurements (190-900 nm.)
Absorption
library(ggplot2) library(tidyr) data("spectra") spectra <- gather(spectra, sample, absorption, -wavelength) ggplot(spectra, aes(x = wavelength, y = absorption, group = sample)) + geom_line(size = 0.1)
library(ggplot2) library(tidyr) data("spectra") spectra <- gather(spectra, sample, absorption, -wavelength) ggplot(spectra, aes(x = wavelength, y = absorption, group = sample)) + geom_line(size = 0.1)
Summary of a CDOM exponential fit
## S3 method for class 'exponential_fit' summary(object, ...)
## S3 method for class 'exponential_fit' summary(object, ...)
object |
An object returned by |
... |
other arguments. |
A numerical vector with estimated coefficients.
data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) summary(fit)
data(spectra) fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900) summary(fit)