Title: Automated and Early Detection of Seasonal Epidemic Onset and Burden Levels
Version: 0.3.0
Description: A powerful tool for automating the early detection of seasonal epidemic onsets in time series data. It offers the ability to estimate growth rates across consecutive time intervals, calculate the sum of cases (SoC) within those intervals, and estimate seasonal onsets within user defined seasons. With use of a disease-specific threshold it also offers the possibility to estimate seasonal onset of epidemics. Additionally it offers the ability to estimate burden levels for seasons based on historical data. It is aimed towards epidemiologists, public health professionals, and researchers seeking to identify and respond to seasonal epidemics in a timely fashion.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
URL: https://github.com/ssi-dk/aedseo, https://ssi-dk.github.io/aedseo/
BugReports: https://github.com/ssi-dk/aedseo/issues
Depends: R (≥ 4.2.0)
Suggests: grid, ISOweek, kableExtra, knitr, mem, rmarkdown, testthat (≥ 3.0.0), tidyr, withr
Config/testthat/edition: 3
Imports: base, checkmate, dplyr, ggplot2, lifecycle, lubridate, plyr, purrr, pracma, rlang, scales, stats, stringr, tibble
Config/Needs/website: rmarkdown
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2025-04-09 08:57:36 UTC; b246418
Author: Sofia Myrup Otero ORCID iD [aut], Kasper Schou Telkamp ORCID iD [aut], Lasse Engbo Christiansen ORCID iD [aut, cre], Rasmus Skytte Randløv ORCID iD [rev], Statens Serum Institut, SSI [cph, fnd]
Maintainer: Lasse Engbo Christiansen <lsec@ssi.dk>
Repository: CRAN
Date/Publication: 2025-04-09 09:20:02 UTC

aedseo: Automated and Early Detection of Seasonal Epidemic Onset and Burden Levels

Description

logo

A powerful tool for automating the early detection of seasonal epidemic onsets in time series data. It offers the ability to estimate growth rates across consecutive time intervals, calculate the sum of cases (SoC) within those intervals, and estimate seasonal onsets within user defined seasons. With use of a disease-specific threshold it also offers the possibility to estimate seasonal onset of epidemics. Additionally it offers the ability to estimate burden levels for seasons based on historical data. It is aimed towards epidemiologists, public health professionals, and researchers seeking to identify and respond to seasonal epidemics in a timely fashion.

Author(s)

Maintainer: Lasse Engbo Christiansen lsec@ssi.dk (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Deprecated aedseo function

Description

[Deprecated] This function has been renamed to better reflect its purpose. Please use seasonal_onset() instead.

Usage

aedseo(...)

Arguments

...

Arguments passed to seasonal_onset()


Autoplot a tsd object

Description

Generates a complete 'ggplot' object suitable for visualizing time series data in a tsd, tsd_onset or tsd_onset_and_burden object.

autoplot(tsd)

autoplot(tsd_onset)

autoplot(tsd_onset_and_burden)

Usage

autoplot(object, ...)

## S3 method for class 'tsd'
autoplot(
  object,
  line_width = 0.7,
  obs_size = 2,
  text_family = "sans",
  time_interval_step = "5 weeks",
  y_label = "Weekly observations",
  ...
)

## S3 method for class 'tsd_onset'
autoplot(
  object,
  disease_color = "black",
  line_width = 0.7,
  obs_size = 2,
  alpha_warning = 0.2,
  alpha_ribbon = 0.1,
  text_family = "sans",
  legend_position = "bottom",
  time_interval_step = "5 weeks",
  y_label = "Weekly observations",
  ...
)

## S3 method for class 'tsd_onset_and_burden'
autoplot(
  object,
  y_lower_bound = 5,
  factor_to_max = 2,
  disease_color = "royalblue",
  season_start = 21,
  season_end = season_start - 1,
  time_interval_step = "3 weeks",
  y_label = "Weekly observations",
  text_burden_size = 10/2.8,
  fill_alpha = c(0.45, 0.6, 0.75, 0.89, 1),
  text_family = "sans",
  line_color = "black",
  line_type = "solid",
  vline_color = "red",
  vline_linetype = "dashed",
  y_scale_labels = scales::label_comma(big.mark = ".", decimal.mark = ","),
  theme_custom = ggplot2::theme_bw(),
  legend_position = "right",
  ...
)

## S3 method for class 'tsd_growth_warning'
autoplot(
  object,
  k = 5,
  skip_current_season = TRUE,
  line_width = 1,
  text_family = "sans",
  legend_position = "bottom",
  breaks_y_axis = 8,
  ...
)

Arguments

object

A tsd_onset object

...

Additional arguments (not used).

line_width

A numeric specifying the width of line connecting observations.

obs_size

A numeric, specifying the size of observational points.

text_family

A character specifying the font family for the text labels.

time_interval_step

A character vector specifying the time interval and how many time steps are desired on the x-axis, e.g. '10 days', '4 weeks', or '3 months'.

y_label

A character vector specifying the y label text.

disease_color

A character specifying the base color of the disease.

alpha_warning

A numeric specifying the alpha (transparency) for the observations with a seasonal_onset_alarm (first plot) or significantly positive growth rate (second plot).

alpha_ribbon

A numeric specifying the alpha for the confidence intervals of the growth rate.

legend_position

A character specifying the position of the legend on the plot.

y_lower_bound

A numeric specifying the lower bound of the y-axis.

factor_to_max

A numeric specifying the factor to multiply the high burden level for extending the y-axis.

season_start, season_end

Integers giving the start and end weeks of the seasons to stratify the observations by.

text_burden_size

A numeric specifying the size of the text labels.

fill_alpha

A numeric vector specifying the transparency levels for the fill colors of burden levels. Must match the number of levels.

line_color

A character specifying the color of the line connecting observations.

line_type

A character specifying the line type for observation line.

vline_color

A character specifying the color of the vertical outbreak start lines.

vline_linetype

A character specifying the line type for outbreak start lines.

y_scale_labels

A function to format y-axis labels.

theme_custom

A function with a ggplot2 theme, specifying the theme to apply to the plot.

k

An integer specifying the window size used to create the tsd_onset object.

skip_current_season

A logical. Do you want to skip your current season?

breaks_y_axis

A numeric specifying how many breaks to show on the y-axis.

Value

A 'ggplot' object for visualizing the tsd data.

A 'ggplot' object for visualizing the tsd_onset data.

A 'ggplot' object for visualizing the tsd_onset_and_burden data for the current season.

A 'ggplot' object for visualizing the tsd_growth_warning data.

Examples

set.seed(345)
# Create an example `tsd` object
time_series <- generate_seasonal_data()
autoplot(time_series)

# Create an `tsd_onset` object
time_series_with_onset <- seasonal_onset(
  tsd = time_series,
  k = 3,
  level = 0.95,
  family = "quasipoisson"
)
autoplot(time_series_with_onset)

# Define `disease_threshold`
disease_threshold <- 150

# Create a `tsd_onset_and_burden` object
tsd_onset_burden <- combined_seasonal_output(
  tsd = time_series,
  disease_threshold = disease_threshold
)
autoplot(tsd_onset_burden)

# Create an `tsd_onset` object
tsd_onset <- seasonal_onset(
  tsd = time_series,
  k = 5,
  family = "quasipoisson",
  season_start = 21,
  only_current_season = FALSE
)

tsd_growth_warning <- consecutive_growth_warnings(tsd_onset)

autoplot(tsd_growth_warning)


Compute seasonal onset and burden levels from seasonal time series observations.

Description

This function performs automated and early detection of seasonal epidemic onsets and estimates the burden levels from time series dataset stratified by season. The seasonal onset estimates growth rates for consecutive time intervals and calculates the sum of cases. The burden levels use the previous seasons to estimate the levels of the current season.

Usage

combined_seasonal_output(
  tsd,
  disease_threshold = 20,
  family = c("poisson", "quasipoisson"),
  family_quant = c("lnorm", "weibull", "exp"),
  season_start = 21,
  season_end = season_start - 1,
  only_current_season = TRUE,
  ...
)

Arguments

tsd

An object containing time series data with 'time' and 'observation.'

disease_threshold

An integer specifying the threshold for considering a disease outbreak. For seasonal onset it defines the per time-step disease threshold that has to be surpassed to possibly trigger a seasonal onset alarm. If the total number of cases in a window of size k exceeds disease_threshold * k, a seasonal onset alarm can be triggered. For burden levels it defines the per time-step disease threshold that has to be surpassed for the observation to be included in the level calculations.

family

A character string specifying the family for modeling seasonal onset.

family_quant

A character string specifying the family for modeling burden levels.

season_start, season_end

Integers giving the start and end weeks of the seasons to stratify the observations by.

only_current_season

Should the output only include results for the current season?

...

Arguments passed to seasonal_burden_levels(), fit_percentiles() and seasonal_onset() functions.

Value

An object containing two lists: onset_output and burden_output:

onset_output:

A seasonal_onset object containing:

burden_output:

A list containing:

Examples

# Generate random flu season
generate_flu_season <- function(start = 1, end = 1000) {
  random_increasing_obs <- round(sort(runif(24, min = start, max = end)))
  random_decreasing_obs <- round(rev(random_increasing_obs))

  # Generate peak numbers
  add_to_max <- c(50, 100, 200, 100)
  peak <- add_to_max + max(random_increasing_obs)

  # Combine into a single observations sequence
  observations <- c(random_increasing_obs, peak, random_decreasing_obs)

 return(observations)
}

season_1 <- generate_flu_season()
season_2 <- generate_flu_season()

start_date <- as.Date("2022-05-29")
end_date <- as.Date("2024-05-20")

weekly_dates <- seq.Date(from = start_date,
                         to = end_date,
                         by = "week")

tsd_data <- tsd(
  observation = c(season_1, season_2),
  time = as.Date(weekly_dates),
  time_interval = "week"
)

# Run the main function
combined_data <- combined_seasonal_output(tsd_data)
# Print seasonal onset results
print(combined_data$onset_output)
# Print burden level results
print(combined_data$burden_output)

Create a tsd_growth_warning object to count consecutive significant observations

Description

This function calculates the number of consecutive significant ("growth_warning") observations, grouping them accordingly. The result is stored in an S3 object of class tsd_threshold.

Uses data from a tsd_onset object (output from seasonal_onset()).

seasonal_onset() has to be run with arguments;

Usage

consecutive_growth_warnings(onset_output)

Arguments

onset_output

A tsd_onset object returned from seasonal_onset().

Value

An object of class tsd_growth_warning, containing; A tibble of processed observations, the significant_counter column specifies when a sequence of significant observation starts and ends. The first number is how many subsequent observations will be significant.

Examples

# Generate simulated data of seasonal waves
sim_data <- generate_seasonal_data(
  years = 5,
  start_date = as.Date("2022-05-26"),
  trend_rate = 1.002,
  noise_overdispersion = 2,
  relative_epidemic_concentration = 3
)

# Estimate seasonal onset
tsd_onset <- seasonal_onset(
  tsd = sim_data,
  family = "quasipoisson",
  season_start = 21,
  season_end = 20,
  only_current_season = FALSE
)

# Get consecutive significant observations
consecutive_growth_warnings(tsd_onset)

Determine Epidemiological Season

Description

This function identifies the epidemiological season, (must span new year) to which a given date belongs. The epidemiological season is defined by a start and end week, where weeks are numbered according to the ISO week date system.

Usage

epi_calendar(date, start = 21, end = 20)

Arguments

date

A date object representing the date to check.

start

An integer specifying the start week of the epidemiological season.

end

An integer specifying the end week of the epidemiological season.

Value

A character vector indicating the season:

Examples

# Check if a date is within the epidemiological season
epi_calendar(as.Date("2023-09-15"), start = 21, end = 20)
# Expected output: "2023/2024"

epi_calendar(as.Date("2023-05-30"), start = 40, end = 20)
# Expected output: "out_of_season"

try(epi_calendar(as.Date("2023-01-15"), start = 1, end = 40))
# Expected error: "`start` must be greater than `end`!"

epi_calendar(as.Date("2023-10-06"), start = 40, end = 11)
# Expected output: "2023/2024"

Fit a growth rate model to time series observations.

Description

This function fits a growth rate model to time series observations and provides parameter estimates along with confidence intervals.

Usage

fit_growth_rate(
  observations,
  level = 0.95,
  family = c("poisson", "quasipoisson")
)

Arguments

observations

A numeric vector containing the time series observations.

level

The confidence level for parameter estimates, a numeric value between 0 and 1.

family

A character string specifying the family for modeling. Choose between "poisson," or "quasipoisson".

Value

A list containing:

Examples

# Fit a growth rate model to a time series of counts
# (e.g., population growth)
data <- c(100, 120, 150, 180, 220, 270)
fit_growth_rate(
  observations = data,
  level = 0.95,
  family = "poisson"
)

Fits weighted observations to distribution and returns percentiles

Description

This function estimates the percentiles of weighted time series observations. The output contains the percentiles from the fitted distribution.

Usage

fit_percentiles(
  weighted_observations,
  conf_levels = c(0.5, 0.9, 0.95),
  family = c("lnorm", "weibull", "exp"),
  optim_method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN", "Brent"),
  lower_optim = -Inf,
  upper_optim = Inf
)

Arguments

weighted_observations

A tibble containing two columns of length n; observation, which contains the data points, and weight, which is the importance assigned to the observation. Higher weights indicate that an observation has more influence on the model outcome, while lower weights reduce its impact.

conf_levels

A numeric vector specifying the confidence levels for parameter estimates. The values have to be unique and in ascending order, that is the lowest level is first and highest level is last.

family

A character string specifying the family for modeling

optim_method

A character string specifying the method to be used in the optimisation. Lookup ?optim::stats for details about methods. If using the exp family it is recommended to use Brent as it is a one-dimensional optimisation.

lower_optim

A numeric value for the optimisation.

upper_optim

A numeric value for the optimisation.

Value

A list containing:

Examples

# Create three seasons with random observations
obs <- 10
season <- c("2018/2019", "2019/2020", "2020/2021")
season_num_rev <- rev(seq(from = 1, to = length(season)))
observations <- rep(stats::rnorm(10, obs), length(season))

# Add into a tibble with decreasing weight for older seasons
data_input <- tibble::tibble(
  observation = observations,
  weight = 0.8^rep(season_num_rev, each = obs)
)

# Use the model
fit_percentiles(
  weighted_observations = data_input,
  conf_levels = c(0.50, 0.90, 0.95),
  family= "weibull"
)

Generate Simulated Data of Seasonal Waves as a tsd object

Description

This function generates a simulated dataset of seasonal waves with trend and noise. This function assumes 365 days, 52 weeks, and 12 months per year. Leap years are not included in the calculation.

Usage

generate_seasonal_data(
  years = 3,
  start_date = as.Date("2021-05-26"),
  amplitude = 100,
  mean = 100,
  phase = 0,
  trend_rate = NULL,
  noise_overdispersion = NULL,
  relative_epidemic_concentration = 1,
  time_interval = c("week", "day", "month"),
  lower_bound = 1e-06
)

Arguments

years

An integer specifying the number of years of data to simulate.

start_date

A date representing the start date of the simulated data.

amplitude

A number specifying the amplitude of the seasonal wave. The output will fluctuate within the range ⁠[mean - amplitude, mean + amplitude]⁠.

mean

A number specifying the mean of the seasonal wave.

phase

A numeric value (in radians) representing the horizontal shift of the sine wave, hence the phase shift of the seasonal wave. The phase must be between zero and 2*pi.

trend_rate

A numeric value specifying the exponential growth/decay rate.

noise_overdispersion

A numeric value specifying the overdispersion of the generated data. 0 means deterministic, 1 is pure poisson and for values > 1 a negative binomial is assumed.

relative_epidemic_concentration

A numeric that transforms the reference sinusoidal season. A value of 1 gives the pure sinusoidal curve, and greater values concentrate the epidemic around the peak.

time_interval

A character vector specifying the time interval. Choose between 'day', 'week', or 'month'.

lower_bound

A numeric value that can be used to ensure that intensities are always greater than zero, which is needed when noise_overdispersion is different from zero.

Value

A tsd object with simulated data containing:

Examples

# Generate simulated data of seasonal waves

#With default arguments
default_sim <- generate_seasonal_data()
plot(default_sim)

#With an exponential growth rate trend
trend_sim <- generate_seasonal_data(trend_rate = 1.001)
plot(trend_sim)

#With noise
noise_sim <- generate_seasonal_data(noise_overdispersion = 2)
plot(noise_sim)

#With distinct parameters, trend and noise
sim_data <- generate_seasonal_data(
  years = 2,
  start_date = as.Date("2022-05-26"),
  amplitude = 2000,
  mean = 3000,
  trend_rate = 1.002,
  noise_overdispersion = 1.1,
  time_interval = c("week")
)
plot(sim_data, time_interval = "2 months")

Summarises estimates like seasonal peak and onset from all available seasons

Description

This function summarises peak timing and seasonal onset from estimates in a tsd_onset object. This can be useful for investigating if the current season falls within estimates from previous seasons or if it is very distinct from previous seasons.

Uses data from a tsd_onset object (output from seasonal_onset()).

seasonal_onset() has to be run with arguments;

Usage

historical_summary(onset_output)

Arguments

onset_output

A tsd_onset object returned from seasonal_onset().

Value

An object of class historical_summary, containing:

Examples

# Generate simulated data of seasonal waves
sim_data <- generate_seasonal_data(
  years = 5,
  start_date = as.Date("2022-05-26"),
  trend_rate = 1.002,
  noise_overdispersion = 1.1
)

# Estimate seasonal onset
tsd_onset <- seasonal_onset(
  tsd = sim_data,
  disease_threshold = 20,
  family = "quasipoisson",
  season_start = 21,
  season_end = 20,
  only_current_season = FALSE
)

# Get historical summary
historical_summary(tsd_onset)

Create a complete 'ggplot' appropriate to a particular data type

Description

This function generates a complete 'ggplot' object suitable for visualizing time series data in tsd, tsd_onset, tsd_onset_and_burden or tsd_growth_warning objects.

Usage

## S3 method for class 'tsd'
plot(x, ...)

## S3 method for class 'tsd_onset'
plot(x, ...)

## S3 method for class 'tsd_onset_and_burden'
plot(x, ...)

## S3 method for class 'tsd_growth_warning'
plot(x, ...)

Arguments

x

An tsd, tsd_onset, tsd_onset_and_burden or tsd_growth_warning object

...

Additional arguments passed to autoplot().

Value

A 'ggplot' object for visualizing output from desired method.

See Also

autoplot()

Examples

# set.seed(321)
# Create and plot `tsd` object
tsd_obj <- generate_seasonal_data(
  years = 3,
  phase = 1,
  start_date = as.Date("2021-10-18")
)
plot(tsd_obj)

disease_threshold <- 150

# Create and plot `tsd_onset` object
tsd_onset_obj <- seasonal_onset(
  tsd = tsd_obj,
  k = 3,
  level = 0.95,
  disease_threshold = disease_threshold,
  family = "quasipoisson"
)
plot(tsd_onset_obj)

# Create a `tsd_onset_and_burden` object
tsd_onset_burden_obj <- combined_seasonal_output(
  tsd = tsd_obj,
  disease_threshold = disease_threshold
)
plot(tsd_onset_burden_obj,
     y_lower_bound = ifelse(disease_threshold < 10, 1, 5))

# Create a `tsd_growth_warning` object
tsd_onset_seasons <- seasonal_onset(
  tsd = tsd_obj,
  season_start = 21,
  family = "quasipoisson",
  only_current_season = FALSE
)
tsd_gr_w <- consecutive_growth_warnings(tsd_onset_seasons)
plot(tsd_gr_w)


Predict Observations for Future Time Steps

Description

This function is used to predict future observations based on a tsd_onset object. It uses the time_interval attribute from the tsd_onset object to make predictions.

Usage

## S3 method for class 'tsd_onset'
predict(object, n_step = 3, ...)

Arguments

object

A tsd_onset object created using the seasonal_onset() function.

n_step

An integer specifying the number of future time steps for which you want to predict observations.

...

Additional arguments (not used).

Value

A tibble-like object called tsd_predict containing the predicted observations, including reference time, lower confidence interval, and upper confidence interval for the specified number of future time steps.

Examples

# Generate predictions of time series data
set.seed(123)
time_series <- generate_seasonal_data(
  years = 1,
  time_interval = "day"
)
# Apply `seasonal_onset` analysis
time_series_with_onset <- seasonal_onset(
  tsd = time_series,
  k = 7
)
# Predict observations for the next 7 time steps
predict(object = time_series_with_onset, n_step = 7)

Compute burden levels from seasonal time series observations of current season.

Description

This function estimates the burden levels of time series observations that are stratified by season. It uses the previous seasons to estimate the levels of the current season. The output is results regarding the current season in the time series observations. NOTE: The data must include data for a complete previous season to make predictions for the current season.

Usage

seasonal_burden_levels(
  tsd,
  family = c("lnorm", "weibull", "exp"),
  season_start = 21,
  season_end = season_start - 1,
  method = c("intensity_levels", "peak_levels"),
  conf_levels = 0.95,
  decay_factor = 0.8,
  disease_threshold = 20,
  n_peak = 6,
  only_current_season = TRUE,
  ...
)

Arguments

tsd

An object containing time series data with 'time' and 'observation.'

family

A character string specifying the family for modeling

season_start, season_end

Integers giving the start and end weeks of the seasons to stratify the observations by.

method

A character string specifying the model to be used in the level calculations. Both model predict the levels of the current series of observations.

  • intensity_levels: models the risk compared to what has been observed in previous seasons.

  • peak_levels: models the risk compared to what has been observed in the n_peak observations each season.

conf_levels

A numeric vector specifying the confidence levels for parameter estimates. The values have to be unique and in ascending order, (i.e. the lowest level is first and highest level is last). The conf_levels are specific for each method:

  • for intensity_levels only specify the highest confidence level e.g.: 0.95, which is the highest intensity that has been observed in previous seasons.

  • for peak_levels specify three confidence levels e.g.: c(0.4, 0.9, 0.975), which are the three confidence levels low, medium and high that reflect the peak severity relative to those observed in previous seasons.

decay_factor

A numeric value between 0 and 1, that specifies the weight applied to previous seasons in level calculations. It is used as decay_factor^(number of seasons back), whereby the weight for the most recent season will be decay_factor^0 = 1. This parameter allows for a decreasing weight assigned to prior seasons, such that the influence of older seasons diminishes exponentially.

disease_threshold

An integer specifying the threshold for considering a disease outbreak. It defines the per time-step disease threshold that has to be surpassed for the observation to be included in the level calculations.

n_peak

A numeric value specifying the number of peak observations to be selected from each season in the level calculations. The n_peak observations have to surpass the disease_threshold to be included.

only_current_season

Should the output only include results for the current season?

...

Arguments passed to the fit_percentiles() function.

Value

A list containing:

Examples

# Generate random flu season
generate_flu_season <- function(start = 1, end = 1000) {
  random_increasing_obs <- round(sort(runif(24, min = start, max = end)))
  random_decreasing_obs <- round(rev(random_increasing_obs))

  # Generate peak numbers
  add_to_max <- c(50, 100, 200, 100)
  peak <- add_to_max + max(random_increasing_obs)

  # Combine into a single observations sequence
  observations <- c(random_increasing_obs, peak, random_decreasing_obs)

 return(observations)
}

season_1 <- generate_flu_season()
season_2 <- generate_flu_season()

start_date <- as.Date("2022-05-29")
end_date <- as.Date("2024-05-20")

weekly_dates <- seq.Date(from = start_date,
                         to = end_date,
                         by = "week")

tsd_data <- tsd(
  observation = c(season_1, season_2),
  time = as.Date(weekly_dates),
  time_interval = "week"
)

# Print seasonal burden results
seasonal_burden_levels(tsd_data, family = "lnorm")

Automated and Early Detection of Seasonal Epidemic Onset

Description

This function performs automated and early detection of seasonal epidemic onsets on a time series dataset. It estimates growth rates for consecutive time intervals and calculates the sum of cases (sum_of_cases).

Usage

seasonal_onset(
  tsd,
  k = 5,
  level = 0.95,
  disease_threshold = NA_integer_,
  family = c("poisson", "quasipoisson"),
  na_fraction_allowed = 0.4,
  season_start = NULL,
  season_end = season_start - 1,
  only_current_season = NULL
)

Arguments

tsd

An object containing time series data with 'time' and 'observation.'

k

An integer specifying the window size for modeling growth rates for the onset.

level

The confidence level for onset parameter estimates, a numeric value between 0 and 1.

disease_threshold

An integer specifying the threshold for considering a disease outbreak. It defines the per time-step disease threshold that has to be surpassed to possibly trigger a seasonal onset alarm. If the total number of cases in a window of size k exceeds disease_threshold * k, a seasonal onset alarm can be triggered.

family

A character string specifying the family for modeling

na_fraction_allowed

Numeric value between 0 and 1 specifying the fraction of observables in the window of size k that are allowed to be NA or zero, i.e. without cases, in onset calculations.

season_start, season_end

Integers giving the start and end weeks of the seasons to stratify the observations by. If set to NULL, it means no stratification by season.

only_current_season

Should the output only include results for the current season?

Value

A seasonal_onset object containing:

Examples

# Create a tibble object from sample data
tsd_data <- tsd(
  observation = c(100, 120, 150, 180, 220, 270),
  time = as.Date(c(
    "2023-01-01",
    "2023-01-02",
    "2023-01-03",
    "2023-01-04",
    "2023-01-05",
    "2023-01-06"
  )),
  time_interval = "day"
)

# Estimate seasonal onset with a 3-day window and a Poisson family model
seasonal_onset(
  tsd = tsd_data,
  k = 3,
  level = 0.95,
  disease_threshold = 20,
  family = "poisson",
  na_fraction_allowed = 0.4,
  season_start = NULL,
  season_end = NULL,
  only_current_season = NULL
)

Summary method for tsd_burden_levels objects

Description

Summarize key results from a seasonal burden levels analysis.

Usage

## S3 method for class 'tsd_burden_levels'
summary(object, ...)

Arguments

object

An object of class 'tsd_burden_levels' containing the results of a seasonal_burden_levels analysis.

...

Additional arguments (not used).

Value

This function is used for its side effect, which is printing the burden levels.

Examples

# Create a `tsd` object
tsd_data <- generate_seasonal_data()

# Create a `tsd_burden_levels` object
tsd_burden_levels <- seasonal_burden_levels(
  tsd = tsd_data
)
# Print the summary
summary(tsd_burden_levels)

Summary method for tsd_onset objects

Description

Summarize key results from a seasonal onset analysis.

Usage

## S3 method for class 'tsd_onset'
summary(object, ...)

Arguments

object

An object of class 'tsd_onset' containing the results of a seasonal_onset analysis.

...

Additional arguments (not used).

Value

This function is used for its side effect, which is printing a summary message to the console.

Examples

# Create a `tsd` object
tsd_data <- generate_seasonal_data()

# Create a `tsd_onset` object
tsd_onset <- seasonal_onset(
  tsd = tsd_data,
  k = 3,
  disease_threshold = 100,
  season_start = 21,
  season_end = 20,
  level = 0.95,
  family = "poisson",
  only_current_season = TRUE
)
# Print the summary
summary(tsd_onset)

Create a tibble-like tsd (time-series data) object from observed data and corresponding dates.

Description

This function takes observations and the corresponding date vector and converts it into a tsd object, which is a time series data structure that can be used for time series analysis.

Usage

to_time_series(observation, time, time_interval = c("day", "week", "month"))

Arguments

observation

A numeric vector containing the observations.

time

A date vector containing the corresponding dates.

time_interval

A character vector specifying the time interval. Choose between 'day', 'week', or 'month'.

Value

A tsd object containing:

Examples

# Create a `tsd` object from daily data
daily_tsd <- to_time_series(
  observation = c(10, 15, 20, 18),
  time = as.Date(
    c("2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04")
  ),
  time_interval = "day"
)

# Create a `tsd` object from weekly data
weekly_tsd <- to_time_series(
  observation = c(100, 120, 130),
  time = as.Date(
    c("2023-01-01", "2023-01-08", "2023-01-15")
  ),
  time_interval = "week"
)

# Create a `tsd` object from monthly data
monthly_tsd <- to_time_series(
  observation = c(500, 520, 540),
  time = as.Date(
    c("2023-01-01", "2023-02-01", "2023-03-01")
  ),
  time_interval = "month"
)


Deprecated tsd function

Description

[Deprecated] This function has been renamed to better reflect its purpose. Please use to_time_series() instead.

Usage

tsd(...)

Arguments

...

Arguments passed to to_time_series()