Learn R Programming

SWMPr (version 2.5.0)

decomp_cj: Simple trend decomposition of monthly swmpr data

Description

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

Usage

decomp_cj(dat_in, ...)

# S3 method for swmpr decomp_cj( dat_in, param, vals_out = FALSE, event = TRUE, type = c("add", "mult"), center = c("mean", "median"), ... )

# S3 method for default decomp_cj( dat_in, param, date_col, vals_out = FALSE, event = TRUE, type = c("add", "mult"), center = c("mean", "median"), ... )

Value

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

Arguments

dat_in

input data object

...

additional arguments passed to or from other methods

param

chr string of variable to decompose

vals_out

logical indicating of numeric output is returned, default is FALSE to return a plot.

event

logical indicating if an 'events' component should be determined

type

chr string indicating the type of decomposition, either additive ('add') or multiplicative ('mult')

center

chr string indicating the method of centering, either 'mean' or 'median'

date_col

chr string indicating the name of the date column which should be a date or POSIX object.

Details

This function is a simple wrapper to the decompTs function in the archived 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.

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

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 = 'mult')

if (FALSE) {
## 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