Title: | 4253H, Twice Smoothing |
---|---|
Description: | Compute Time series Resistant Smooth 4253H, twice smoothing method. |
Authors: | Muntashir-Al-Arefin, Prof. Md. Ayub Al. |
Maintainer: | Muntashir-Al-Arefin <[email protected]> |
License: | GPL-3 |
Version: | 1.0.2 |
Built: | 2025-01-30 05:52:29 UTC |
Source: | https://github.com/cran/sleekts |
In Time Series Resistant Smooth offers 4253H, twice smoothing method.
sleek(y)
sleek(y)
y |
a vector or time series |
4253H, twice consisting of a running median of 4, then 2, then 5, then 3 followed by Hanning. Endpoints are always handled using smoothers of shorter, even span or odd span. Hanning is a running weighted average, the weights being 1/4, 1/2 and 1/4. The result of this smoothing is then reroughed by computing residuals, applying the same smoother to them and adding the result to the smooth of the first pass. The endpoint rule modifies the values first and last values of series.
vector or time series of smoothed values of the same length as x
Muntashir-Al-Arefin [email protected] based on R.
Velleman, P. F. 1980. Definition and comparison of robust nonlinear data smoothing algorithms. Journal of the American Statistical Association 75: 609-61.
Velleman, P. F., and D. C. Hoaglin. 1981. Applications, Basics, and Computing of Exploratory Data Analysis. Boston: Duxbury.
Tukey, J. W. 1977. Exploratory Data Analysis. Reading, MA: Addison-Wesley.
Velleman, P. F. 1977. Robust nonlinear data smoothers: Definitions and recommendations. Proceedings of the National Academy of Sciences 74: 434-436.
##Example of sleek function using time series data tsdata #(GDP per capita Bangladesh, currency gold in ounce) in sleekts package: library(sleekts) data(tsData) tsData sleek(tsData) # To see original data plot and smoothed data plot par(mfrow = c(2, 1)) plot(tsData); plot(sleek(tsData)); ## The function is currently defined as function (y) { h <- function(y) { N <- length(y) z <- NULL z[1] <- y[1] z[2] <- median(c(y[1], y[2])) z[3] <- median(c(y[2], y[3])) for (i in 4:(N)) { z[i] <- median(c(y[i - 3], y[i - 2], y[i - 1], y[i])) } z[N - 1] <- median(c(y[N - 2], y[N - 1])) z[N] <- median(c(y[N - 1], y[N])) z[N + 1] <- y[N] z1 <- NULL for (i in 1:N) { z1[i] <- (z[i] + z[i + 1])/2 } z2 <- NULL z2[1] <- z1[1] z2[2] <- median(c(z1[1], z1[2], z1[3])) for (i in 3:(N - 2)) { z2[i] <- median(c(z1[i - 2], z1[i - 1], z1[i], z1[i + 1], z1[i + 2])) } z2[N - 1] <- median(c(z1[N - 2], z1[N - 1], z1[N])) z2[N] <- z1[N] z3 <- NULL z3[1] <- z2[1] for (i in 2:(N - 1)) { z3[i] <- median(c(z2[i - 1], z2[i], z2[i + 1])) } z3[N] <- z2[N] z4 <- NULL z4[1] <- z3[1] for (i in 2:(N - 1)) { z4[i] <- (z3[i - 1] + z3[i] + z3[i + 1])/4 } z4[N] <- z3[N] z4[1] <- median(c(z4[1], z4[2], (3 * z4[2] - 2 * z4[3]))) z4[N] <- median(c(z4[N], z4[N - 1], (3 * z4[N - 2] - 2 * z4[N - 1]))) return(z4) } sm <- h(y) rf <- (y - sm) sm.rf <- h(rf) smooth <- (sm.rf + sm) if (is.ts(y) == 1) { date <- start(y) smooth <- ts(smooth, start = date) } return(smooth) }
##Example of sleek function using time series data tsdata #(GDP per capita Bangladesh, currency gold in ounce) in sleekts package: library(sleekts) data(tsData) tsData sleek(tsData) # To see original data plot and smoothed data plot par(mfrow = c(2, 1)) plot(tsData); plot(sleek(tsData)); ## The function is currently defined as function (y) { h <- function(y) { N <- length(y) z <- NULL z[1] <- y[1] z[2] <- median(c(y[1], y[2])) z[3] <- median(c(y[2], y[3])) for (i in 4:(N)) { z[i] <- median(c(y[i - 3], y[i - 2], y[i - 1], y[i])) } z[N - 1] <- median(c(y[N - 2], y[N - 1])) z[N] <- median(c(y[N - 1], y[N])) z[N + 1] <- y[N] z1 <- NULL for (i in 1:N) { z1[i] <- (z[i] + z[i + 1])/2 } z2 <- NULL z2[1] <- z1[1] z2[2] <- median(c(z1[1], z1[2], z1[3])) for (i in 3:(N - 2)) { z2[i] <- median(c(z1[i - 2], z1[i - 1], z1[i], z1[i + 1], z1[i + 2])) } z2[N - 1] <- median(c(z1[N - 2], z1[N - 1], z1[N])) z2[N] <- z1[N] z3 <- NULL z3[1] <- z2[1] for (i in 2:(N - 1)) { z3[i] <- median(c(z2[i - 1], z2[i], z2[i + 1])) } z3[N] <- z2[N] z4 <- NULL z4[1] <- z3[1] for (i in 2:(N - 1)) { z4[i] <- (z3[i - 1] + z3[i] + z3[i + 1])/4 } z4[N] <- z3[N] z4[1] <- median(c(z4[1], z4[2], (3 * z4[2] - 2 * z4[3]))) z4[N] <- median(c(z4[N], z4[N - 1], (3 * z4[N - 2] - 2 * z4[N - 1]))) return(z4) } sm <- h(y) rf <- (y - sm) sm.rf <- h(rf) smooth <- (sm.rf + sm) if (is.ts(y) == 1) { date <- start(y) smooth <- ts(smooth, start = date) } return(smooth) }
"tsData" is a time series data of GDP per capita Bangladesh, currency gold in ounce .
data("tsbd")
data("tsbd")
The format is: Time-Series [1:55] from 1960 to 2014: 2.45 2.68 2.75 2.81 2.76 ...
tsData is calculated as GDP per capita (current US$) divided by London Bullion Market U.S. Dollars per Troy Ounce. [ Note: Some values of this series tsData are estimated. It's not accurate data. It can be use only for practice time series analysis in R.]
https://datamarket.com/data/set/15c9/gdp-per-capita-current-us#!ds=15c9!hd1=3r&display=line
https://datamarket.com/data/set/4npz/gold-fixing-price#!ds=4npz!81t9=2:81tb=3.2&display=line
Federal Reserve Bank of St. Louis
data(tsbd) plot(tsbd)
data(tsbd) plot(tsbd)
"tsData" is a time series data of GDP per capita Bangladesh, currency gold in ounce.
data("tsData")
data("tsData")
The format is: Time-Series [1:55] from 1960 to 2014: 2.45 2.68 2.75 2.81 2.76 ...
tsData is calculated as GDP per capita (current US$) divided by London Bullion Market U.S. Dollars per Troy Ounce. [ Note: Some values of this series tsData are estimated. It's not accurate data. It can be use only for practice time series analysis in R.]
https://datamarket.com/data/set/15c9/gdp-per-capita-current-us#!ds=15c9!hd1=3r&display=line
https://datamarket.com/data/set/4npz/gold-fixing-price#!ds=4npz!81t9=2:81tb=3.2&display=line
Federal Reserve Bank of St. Louis
data(tsData) plot(tsData)
data(tsData) plot(tsData)