Created
March 12, 2022 10:30
-
-
Save MJacobs1985/b6765a7a27ba00a4a49b62e50b19da2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot(ts(mymts[,1])) | |
# DWT with level of 2^3 | |
data_dwt <- repr_dwt(mymts[,1], level = 6); length(data_dwt) | |
# first 84 DFT coefficients are extracted and then inverted | |
data_dft <- repr_dft(mymts[,1], coef = 63); length(data_dft) | |
# first 84 DCT coefficients are extracted and then inverted | |
data_dct <- repr_dct(mymts[,1], coef = 63); length(data_dct) | |
# Classical PAA | |
data_paa <- repr_paa(mymts[,1], q = 65, func = mean); length(data_paa) | |
data_plot <- data.frame(Value = c(data_dwt, data_dft, data_dct, data_paa), | |
Time = rep(1:length(data_dwt), 4), | |
Method = factor(rep(c("DWT", "DFT", "DCT", "PAA"), | |
each = length(data_dwt)))) | |
ggplot(data_plot, aes(Time, Value, color = Method)) + | |
geom_line(alpha = 0.80, size = 0.8) + theme_bw() | |
data_lm <- repr_lm(mymts[,1], freq = 63, method = "lm"); length(data_lm) | |
# robust linear model and l1 regression are also implemented | |
data_l1 <- repr_lm(mymts[,1], freq = 63, method = "l1"); length(data_l1) | |
# GAM | |
data_gam <- repr_gam(mymts[,1], freq = 63); length(data_gam) | |
# median seasonal profile | |
data_seas_prof <- repr_seas_profile(mymts[,1], freq = 63, func = median); length(data_seas_prof ) | |
# exponential smoothing | |
data_exp <- repr_exp(mymts[,1], freq = 63); length(data_exp) | |
data_plot <- data.frame(Value = c(data_lm, data_l1, data_seas_prof, data_exp, data_gam), | |
Time = c(rep(1:length(data_lm), 4), 1:length(data_gam)), | |
Method = c(rep(c("LM", "L1", "Median seas. prof.", "Exp. smooth."), | |
each = 63), rep("GAM", 62))) | |
ggplot(data_plot, aes(Time, Value, color = Method)) + | |
geom_line(alpha = 0.80, size = 0.8) + | |
theme_bw() | |
data_pip <- repr_pip(mymts[,1], times = 60, return = "both") | |
data_pla <- repr_pla(mymts[,1], times = 60, return = "both") | |
data_plot <- data.frame(Value = c(mymts[,1], data_pip$points, data_pla$points), | |
Time = c(1:length(mymts[,1]), data_pip$places, data_pla$places), | |
Method = c(rep("Original", length(mymts[,1])), | |
rep(c("PIP", "PLA"), each = length(data_pla$places)))) | |
ggplot(data_plot, aes(Time, Value, color = Method)) + | |
geom_line(alpha = 0.65, size = 0.8) + | |
theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment