Package 'cdom'

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

Help Index


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=a0e(S(xλ0))+Ky = 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=S275295S350400SR = \frac{S_{275-295}}{S_{350-400}}

Value

The value of the slope ratio.

References

http://www.aslo.org/lo/toc/vol_53/issue_3/0955.html

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

http://doi.wiley.com/10.4319/lo.2009.54.2.0590

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 cdom_exponential.

...

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 cdom_exponential.

...

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 cdom_exponential.

...

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 cdom_exponential.

...

other arguments.

Value

A numerical vector with estimated coefficients.

Examples

data(spectra)

fit <- cdom_exponential(spectra$wavelength, spectra$spc1, 350, 190, 900)
summary(fit)