View source: R/aSerfling_predict.R
aSerfling_predict | R Documentation |
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.
aSerfling_predict(sf, df_test)
sf |
Model object from |
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. |
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:
Test data must maintain the same time resolution (weekly/monthly) as training data
The first test observation must be the immediate next time point after the last training observation
Column names and cycle parameters must match the original model specification
A data frame containing warning results. The value of the warning column is 1 for warning and 0 for no warning.
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.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.