Skip to contents

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_periodicity object from detect_periodicity().

value_col

Column name for values if x is a data frame. Default "value".

time_col

Column name for time if x is a data frame. Default "monyear". Parsed via parse_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. TRUE if 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().

Examples

if (FALSE) { # \dontrun{
births <- get_hmis("Number of female live births",
  state = "Kerala", category = "Total", sector = "Total"
)
result <- detect_periodicity(births)
print(result)
plot(result)
} # }