dpdetrend {densitr}R Documentation

Detrend (remove a trend) a density profile either using linear or GAM regression

Description

This function will take a dp object and remove the trend from the measurement either by fitting a linear regression or by fitting a GAM regression using REML. The trend is then subtracted from the actual data and a detrended dp object is returned. Be advised detrending should be done on measurements without the starting or ending point, e.g. they should be trimmed. GAM is more useful in tree ring detection, while linear regression is more commonly used for further analysis of the density data. GAM requires mcgv package to run.

Usage

dpdetrend(dp, type = "")

Arguments

dp

A dp object, see dpload.

type

Either "linear" for a fitting linear regression or "gam" for a GAM fit using REML.

Value

A dp object without the trend.

See Also

dptrim, dptriml, dptrim_s, dptriml_s

Examples

## load a single file
dp <- dpload(system.file("extdata", "00010001.dpa", package = "densitr"))
## load several dp objects
dp.list <- dpload(dp.directory = system.file("extdata", package = "densitr"))
## trim the measurement
dp.trimmed <- dptrim(dp)
## detrend the measurement
dp.detrended <- dpdetrend(dp, type = "linear")
## detrend a list without displaying progress
dp.list.detrended <- lapply(dp.list, dpdetrend, type = "linear")
## detrend a list with displaying progress and run in parallel to
## speed things up - requires pbapply library, adjust the cl argument to
## desired number of cores

dp.list.detrended <- pbapply::pblapply(dp.list, dpdetrend, type = "linear", cl = 1)


[Package densitr version 0.2 Index]