View source: R/WhittakerSmooth.R
| WhittakerSmooth | R Documentation |
This function applies the Whittaker-Eilers smoothing and interpolation method
to a specified pollutant in a data frame. The method is based on penalised
least squares and is designed to handle time series data with missing values,
providing a smoothed estimate of the pollutant concentrations over time. The
function allows for flexible control over the amount of smoothing through the
lambda parameter and can be applied to multiple pollutants simultaneously.
WhittakerSmooth(
mydata,
pollutant = "o3",
lambda = 24L,
d = 2,
type = "default",
new.name = NULL,
date.pad = FALSE,
p = NULL,
...
)
mydata |
A data frame containing a |
pollutant |
The name of a pollutant, e.g., |
lambda |
The value of |
d |
The order used to penalise the roughness of the data. By default
this is set to 2, which penalises the second derivative of the data.
Setting |
type |
Used for splitting the data further. Passed to |
new.name |
The name given to the new column(s). If not supplied it will create a name based on the name of the pollutant. |
date.pad |
Should missing dates be padded? Default is |
p |
The asymmetry weight parameter used exclusively for baseline estimation (Asymmetric Least Squares). It defines how the algorithm treats points that fall above the fitted line versus points that fall below it. It takes a value between 0 and 1. When p is very small, the algorithm assigns a massive penalty to the curve if it rises above the data points, but almost no penalty if it drops below them. This forces the curve to "hug" the bottom of the signal, effectively ignoring the positive peaks. Typical Values: 0.01 to 0.05. |
... |
Additional parameters passed to |
In addition to smoothing, the function can also perform baseline estimation
using Asymmetric Least Squares (ALS) when the p parameter is provided. This
allows for the separation of the underlying baseline from the observed data,
which can be particularly useful for identifying trends or correcting for
background levels in pollutant concentrations.
The function is designed to work with regularly spaced time series.
A tibble with new columns for the smoothed pollutant values.
David Carslaw
Paul H. C. Eilers, A Perfect Smoother, Analytical Chemistry 2003 75 (14), 3631-3636, DOI: 10.1021/ac034173t
# Smoothing with lambda = 24
mydata <- WhittakerSmooth(mydata, pollutant = "o3", lambda = 24)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.