| Type: | Package |
| Title: | R Functions to Model CDOM Spectra |
| Version: | 0.1.1 |
| Date: | 2026-05-12 |
| Description: | Wrapper functions to model and extract various quantitative information from absorption spectra of chromophoric dissolved organic matter (CDOM). |
| BugReports: | https://github.com/PMassicotte/cdom/issues |
| URL: | https://github.com/PMassicotte/cdom |
| Encoding: | UTF-8 |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| Depends: | R (≥ 3.0) |
| LazyData: | TRUE |
| Imports: | minpack.lm, ggplot2, tidyr, broom, purrr |
| RoxygenNote: | 7.3.3 |
| Suggests: | eemR |
| NeedsCompilation: | no |
| Packaged: | 2026-05-12 13:25:57 UTC; filoche |
| Author: | Philippe Massicotte [aut, cre] |
| Maintainer: | Philippe Massicotte <pmassicotte@hotmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-12 14:10:07 UTC |
Fit an exponential model to CDOM data.
Description
Fit an exponential model to CDOM data.
Usage
cdom_exponential(wl, absorbance, wl0 = 350, startwl, endwl)
Arguments
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). |
Details
y = a0 * e^{(-S(x - \lambda_0))} + K
Value
A list containing:
- params
A data frame with values of fitted parameters.
- r2
R2 of the nls model.
- data
A data frame with fitted (predicted) values of the model.
The function will return NULL if the model did not converged.
Examples
# 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.
Description
Calculate the slope ratio (SR) from an absorption spectra.
Usage
cdom_slope_ratio(wl, absorbance)
Arguments
wl |
The wavelength vector. |
absorbance |
The absorbance vector. |
Details
Calculate the slope ratio (SR) as defined by Helms et al. (2008).
SR = \frac{S_{275-295}}{S_{350-400}}
Value
The value of the slope ratio.
References
Examples
data("spectra")
cdom_slope_ratio(spectra$wavelength, spectra$spc1)
Calculate the spectral curve of CDOM spectra.
Description
Calculate the spectral curve of CDOM spectra has proposed by Loiselle et al. 2009.
Usage
cdom_spectral_curve(wl, absorbance, interval = 21, r2threshold = 0.8)
Arguments
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. |
Value
A dataframe containing the centered wavelength, the calculated slope and the determination coefficient of the linear regression used to claculate the slope.
References
Examples
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
Description
Extract Model Coefficients from a CDOM exponential fit
Usage
## S3 method for class 'exponential_fit'
coef(object, ...)
Arguments
object |
An object returned by |
... |
other arguments. |
Value
A numerical vector with estimated coefficients.
Examples
data(spectra)
fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900)
coef(fit)
Plot a Fitted CDOM Exponential Curve
Description
Plot a Fitted CDOM Exponential Curve
Usage
## S3 method for class 'exponential_fit'
plot(x, ...)
Arguments
x |
An object returned by |
... |
other arguments. |
Value
A ggplot2 object.
Examples
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
Description
Predict method for CDOM exponential fit
Usage
## S3 method for class 'exponential_fit'
predict(object, ...)
Arguments
object |
An object returned by |
... |
other arguments. |
Value
A numerical vector with predicted values.
Examples
data(spectra)
fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900)
predict(fit)
CDOM absorption data.
Description
Simple absorption spectra used to test package's functions.
Usage
data(spectra)
Format
A data frame with 711 rows and 26 variables
Details
wavelength. Wavelengths used for measurements (190-900 nm.)
Absorption
Examples
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
Description
Summary of a CDOM exponential fit
Usage
## S3 method for class 'exponential_fit'
summary(object, ...)
Arguments
object |
An object returned by |
... |
other arguments. |
Value
A numerical vector with estimated coefficients.
Examples
data(spectra)
fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900)
summary(fit)