Uses spectral analysis (periodogram) and autocorrelation to determine if a numeric time series has periodic/seasonal patterns.
Usage
detect_periodicity(
x,
value_col = "value",
time_col = "monyear",
detrend = TRUE
)
# S3 method for class 'hmis_periodicity'
plot(x, ...)Arguments
- x
An
hmis_periodicityobject fromdetect_periodicity().- value_col
Column name for values if
xis a data frame. Default"value".- time_col
Column name for time if
xis a data frame. Default"monyear". Parsed viaparse_monyear()if character.- detrend
Logical. Remove linear trend before analysis. Default
TRUE.- ...
Additional arguments (ignored).
Value
A list with class "hmis_periodicity" containing:
- is_periodic
Logical.
TRUEif significant periodicity detected.- dominant_period
Dominant period in number of observations (e.g., 12 for monthly data with annual cycle).
- spectral_power
Relative spectral power at the dominant frequency.
- acf_peak
Autocorrelation at the dominant lag.
- frequencies
Data frame of top frequencies with periods and power.
- spectrum
The raw spectrum object from
stats::spec.pgram().