# NOT RUN {
library(tidyverse)
library(timetk)
options(max.print = 50)
date_sequence <- tk_make_timeseries("2016-01-01", "2016-01-31", by = "hour")
# --- VECTOR ---
fourier_vec(date_sequence, period = 7 * 24, K = 1, type = "sin")
# --- MUTATE ---
tibble(date = date_sequence) %>%
# Add cosine series that oscilates at a 7-day period
mutate(
C1_7 = fourier_vec(date, period = 7*24, K = 1, type = "cos"),
C2_7 = fourier_vec(date, period = 7*24, K = 2, type = "cos")
) %>%
# Visualize
pivot_longer(cols = contains("_"), names_to = "name", values_to = "value") %>%
plot_time_series(
date, value, .color_var = name,
.smooth = FALSE,
.interactive = FALSE,
.title = "7-Day Fourier Terms"
)
# }
Run the code above in your browser using DataLab