fourier_vars: Create Fourier (trigonometric) regressors for weekly data

View source: R/fourier_vars.R

fourier_varsR Documentation

Create Fourier (trigonometric) regressors for weekly data

Description

Constructs sine and cosine regressors to capture seasonal variation at intrayearly and intramonthly frequencies in weekly time series. The Fourier terms are defined using the day-of-year and day-of-month corresponding to each observation date, allowing the seasonal frequencies to adapt to varying month and year lengths.

Usage

fourier_vars(k = 1, l = 1, dates)

Arguments

k

Integer. Number of yearly-cycle Fourier harmonics (pairs of sine and cosine terms) to include.

l

Integer. Number of monthly-cycle Fourier harmonics (pairs of sine and cosine terms) to include.

dates

A vector of class "Date" corresponding to the observation dates.

Value

A numeric matrix with length(dates) rows and 2 * (k + l) columns containing the Fourier regressors. Columns are ordered with yearly terms first, followed by monthly terms. If both k = 0 and l = 0, NULL is returned.

Examples


# create a vector of dates
dates=seq.Date(from=as.Date("2023-01-02"),by="weeks",length.out = 100)
# Create a matrix with 20 yearly and 6 monthly pairs of sine and cosine variables
X=fourier_vars(k=20,l=6,dates=dates)


boiwsa documentation built on Dec. 14, 2025, 5:06 p.m.