View source: R/vec-hai-fourier-discrete.R
hai_fourier_discrete_vec | R Documentation |
Takes a numeric vector or date and will return a vector of one of the following:
"sin"
"cos"
"sincos" This will do value = sin(x) * cos(x) When either of these values falls below zero, then zero else one
hai_fourier_discrete_vec(
.x,
.period,
.order,
.scale_type = c("sin", "cos", "sincos")
)
.x |
A numeric vector |
.period |
The number of observations that complete a cycle |
.order |
The fourier term order |
.scale_type |
A character of one of the following: "sin","cos","sincos" |
Takes a numeric vector or date and will return a vector of one of the following:
"sin"
"cos"
"sincos"
The internal caluclation is straightforward:
sin = sin(2 * pi * h * x)
, where h = .order/.period
cos = cos(2 * pi * h * x)
, where h = .order/.period
sincos = sin(2 * pi * h * x) * cos(2 * pi * h * x)
where h = .order/.period
This function can be used on its own. It is also the basis for the function
hai_fourier_discrete_augment()
.
A numeric vector of 1's and 0's
Steven P. Sanderson II, MPH
Other Vector Function:
hai_fourier_vec()
,
hai_hyperbolic_vec()
,
hai_kurtosis_vec()
,
hai_scale_zero_one_vec()
,
hai_scale_zscore_vec()
,
hai_skewness_vec()
,
hai_winsorized_move_vec()
,
hai_winsorized_truncate_vec()
suppressPackageStartupMessages(library(dplyr))
len_out <- 24
by_unit <- "month"
start_date <- as.Date("2021-01-01")
data_tbl <- tibble(
date_col = seq.Date(from = start_date, length.out = len_out, by = by_unit),
a = rnorm(len_out),
b = runif(len_out)
)
vec_1 <- hai_fourier_discrete_vec(data_tbl$a, .period = 12, .order = 1, .scale_type = "sin")
vec_2 <- hai_fourier_discrete_vec(data_tbl$a, .period = 12, .order = 1, .scale_type = "cos")
vec_3 <- hai_fourier_discrete_vec(data_tbl$a, .period = 12, .order = 1, .scale_type = "sincos")
plot(data_tbl$b)
lines(vec_1, col = "blue")
lines(vec_2, col = "red")
lines(vec_3, col = "green")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.