rsurveillance

Convert dataframe to list for Farrington algorithm algo.farrington


I have the following example data frame:

data.frame(WEEK=c(1:10),YEAR=2000,
           NUMBER=c(0,1,4,25,9,7,4,2,9,12))

   WEEK YEAR NUMBER
1     1 2000      0
2     2 2000      1
3     3 2000      4
4     4 2000     25
5     5 2000      9
6     6 2000      7
7     7 2000      4
8     8 2000      2
9     9 2000      9
10   10 2000     12

I want to use the Farrington algorithm algo.farrington from the surveillance package in R. However, in order to do so my data have to be an object of class disProgObj. Based on the example I found in the PDF of the surveillance package the result should be a list.

Does anyone know how to convert my data so I can get the algorithm to work?


Solution

  • To handle such data, the R package surveillance provides the S4 class "sts" (surveillance time series), which supersedes the "disProg" class. To convert your data to an "sts" object:

    x <- data.frame(WEEK=c(1:10), YEAR=2000, NUMBER=c(0,1,4,25,9,7,4,2,9,12))
    xsts <- sts(observed = x$NUMBER, start = c(2000, 1), frequency = 52)
    xsts
    

    which yields:

    -- An object of class sts -- 
    freq:        52 
    start:       2000 1 
    dim(observed):   10 1 
    
    Head of observed:
         observed1
    [1,]         0
    

    This "sts" object could be converted to the obsolete "disProg" class via sts2disProg() as illustrated in Roman's answer. However, this conversion is not necessary since the function farrington() can be used directly with an "sts" object (it internally calls algo.farrington()).

    The package authors encourage the use of the newer "sts" class to encapsulate count time series. See the package vignette("monitoringCounts") published at http://doi.org/10.18637/jss.v070.i10 for a description of the outbreak detection tools.