Learn R Programming

SWMPr (version 2.1.5)

decomp_cj: Simple trend decomposition of monthly swmpr data

Description

Decompose monthly SWMP time series into grandmean, annual, seasonal, and event series using decompTs, as described in Cloern and Jassby 2010.

Usage

decomp_cj(dat_in, ...)
"decomp_cj"(dat_in, param, vals_out = FALSE, ...)
"decomp_cj"(dat_in, param, date_col, vals_out = FALSE, ...)

Arguments

dat_in
input data object
...
additional arguments passed to other methods, including decompTs
param
chr string of variable to decompose
vals_out
logical indicating of numeric output is returned, default is FALSE to return a plot.
date_col
chr string indicating the name of the date column which should be a date or POSIX object.

Value

A ggplot object if vals_out = TRUE (default), otherwise a monthly time series matrix of class ts.

Details

This function is a simple wrapper to the decompTs function in the wq package, also described in Cloern and Jassby (2010). The function is similar to decomp.swmpr (which is a wrapper to decompose) with a few key differences. The decomp.swmpr function decomposes the time series into a trend, seasonal, and random components, whereas the current function decomposes into the grandmean, annual, seasonal, and events components. For both functions, the random or events components, respectively, can be considered anomalies that don't follow the trends in the remaining categories.

The decomp_cj function provides only a monthly decomposition, which is appropriate for characterizing relatively long-term trends. This approach is meant for nutrient data that are obtained on a monthly cycle. The function will also work with continuous water quality or weather data but note that the data are first aggregated on the monthly scale before decomposition. Use the decomp.swmpr function to decompose daily variation.

Additional arguments passed to decompTs can be used with decomp_cj, such as startyr, endyr, and type. Values passed to type are mult (default) or add, referring to multiplicative or additive decomposition. See the documentation for decompTs for additional explanation and examples.

References

Cloern, J.E., Jassby, A.D. 2010. Patterns and scales of phytoplankton variability in estuarine-coastal ecosystems. Estuaries and Coasts. 33:230-241.

See Also

decompTs, ts

Examples

Run this code
## get data
data(apacpnut)
dat <- apacpnut
dat <- qaqc(dat, qaqc_keep = NULL)

## decomposition of chl, values as data.frame
decomp_cj(dat, param = 'chla_n', vals_out = TRUE)

## decomposition of chl, ggplot
decomp_cj(dat, param = 'chla_n')

## decomposition changing arguments passed to decompTs
decomp_cj(dat, param = 'chla_n', type = 'add')

## monthly decomposition of continuous data
data(apacpwq)
dat2 <- qaqc(apacpwq)

decomp_cj(dat2, param = 'do_mgl')

## using the default method with a data frame
dat <- data.frame(dat)
decomp_cj(dat, param = 'chla_n', date_col = 'datetimestamp')

Run the code above in your browser using DataLab