smooth_s2ts | R Documentation |
Smooth time series extracted with function extract_s2ts()
using a Savitzky-Golay filter.
Quality flags associated to the time series are used to obtain better
results.
Argument values should be manually set to obtain a correct smoothing.
smooth_s2ts(
ts,
min_qa = 0.2,
noise_dir = "low",
spike = 0.25,
spike_window = 5,
sg_daywindow = 15,
sg_polynom = 2,
sg_n = 3,
max_extrapolation = 0.1
)
ts |
Time series in |
min_qa |
(optional) minimum 0-1 quality value
(points with |
noise_dir |
Direction of points generally containing noise.
If |
spike |
Relative "y" difference for spike determination (default is 0.25). Set to NA to skip spike removal. |
spike_window |
Maximum number of values for spike identification (it must be an odd number). Default is 3. |
sg_daywindow |
Half-size of the time window to be used to interpolate |
sg_polynom |
Argument |
sg_n |
(optional) Positive integer: number of applications of the
Savitzky-Golay filter. The minimum value is 1 (a single application
using the weights included in |
max_extrapolation |
(optional) Numeric: maximum allowed extrapolation out of original range (relative value). Default is 0.1 (+10%). Set to Inf in order not to set any constraint. |
The output time series in s2ts
format.
Luigi Ranghetti, PhD (2020) luigi@ranghetti.info
# Load input data
data("ts_raw")
# Smoothing time series using default parameters
ts_smoothed <- smooth_s2ts(ts_raw)
print(ts_smoothed, topn = 5) # standard print
head(as.data.frame(ts_smoothed)) # see content
plot(ts_smoothed)
# Apply a more pronounced smoothing
ts_smoothed_2 <- smooth_s2ts(
ts_raw,
min_qa = 0.5, # exclude values with qa < 0.5
sg_daywindow = 30, # larger moving window
sg_polynom = 3, # cubic interpolation
sg_n = 5 # apply the SG filter 5 times
)
plot(ts_smoothed_2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.