aSerfling_predict: Apply Adjusted Serfling Model to Subsequent Time Periods

View source: R/aSerfling_predict.R

aSerfling_predictR Documentation

Apply Adjusted Serfling Model to Subsequent Time Periods

Description

Projects an existing Serfling model onto new temporally contiguous data to detect epidemic signals. Requires test data to immediately follow training data chronologically to maintain periodicity.

Usage

aSerfling_predict(sf, df_test)

Arguments

sf

Model object from aSerfling (must contain best_fit, output, and cycles components)

df_test

New data frame with identical structure to training data, containing subsequent time points. Must include the response variable column used in original modeling.

Details

This function extends the surveillance capability of an established aSerfling model by:

  • Automatically generating time indices continuing from the training set

  • Preserving all terms from the original model fit

  • Calculating prediction intervals using the trained coefficients

  • Flagging values exceeding the 95% upper prediction bound as warnings

Critical requirements:

  1. Test data must maintain the same time resolution (weekly/monthly) as training data

  2. The first test observation must be the immediate next time point after the last training observation

  3. Column names and cycle parameters must match the original model specification

Value

A data frame containing warning results. The value of the warning column is 1 for warning and 0 for no warning.

References

Wang X, Wu S, MacIntyre CR, et al. Using an adjusted Serfling regression model to improve the early warning at the arrival of peak timing of influenza in Beijing. PLoS One, 2015,10(3):e0119923.

Examples

data(sample_ili)

## Split into sequential training/test sets
df_train <- sample_ili[1:150,]
df_test <- sample_ili[151:200,]

## modeling
sf <- aSerfling(df_train, 'case', cycles = c(52, 26))

## apply the model to test set
pre <- aSerfling_predict(sf, df_test)

## visualize alerts
plot(pre$date, pre$case, type = "l")
points(pre$date[pre$warning == 1],
       pre$case[pre$warning == 1], col = "red")


WarnEpi documentation built on Aug. 27, 2025, 9:10 a.m.