Learn R Programming

surveillance (version 1.5-4)

linelist2sts: Convert individual case information based on dates into an aggregated time series

Description

The function is used to convert an individual line list of cases to an aggregated time series based on date information of the cases.

Usage

linelist2sts(linelist,dateCol,aggregate.by="1 week",dRange=NULL,
            startYearFormat=switch(aggregate.by,
"1 day"="%V","7 day"="%V","1 week"="%V","1 month"="%Y","3 month"="%Y"),
           startEpochFormat=switch(aggregate.by,
"1 day"="%j","7 day"="%V","1 week"="%V","1 month"="%m","3 month"="%Q")
)

Arguments

linelist
A data.frame containing the line list of cases.
dateCol
A character string stating the column name in linelist which contain the case data which are to be temporally aggregated.
aggregate.by
Temporal aggregation level given as a string, see the by variable of the seq.Date function for further details.
dRange
A vector containing the minimum and maximum data to use. If not specified these dates are extracted automatically by taking range(D[,dateCol]).
startYearFormat
Strptime compatible format string to use for determining how the date string is generated. Usually the provided options are sufficient.
startEpochFormat
Strptime compatible format string to use for determining how the date string is generated. Usually the provided options are sufficient.

Value

  • The function returns an object of class "sts". The freq slot might not be appropriate.

encoding

latin1

Details

In case aggregation occurs by week the date range is automatically extended such that the starting and ending dates are mondays. This might not be an appropriate way in all situations this function is to be used.

See Also

See also seq.Date.

Examples

Run this code
#Load simulated outbreak data.
url <- paste("http://www.stat.uni-muenchen.de/~hoehle/",
             "teaching/moid2011/tutorials/cast-backnow/outbreak.txt",sep="")
D <- try(read.table(url,header=TRUE,colClasses=c("integer",rep("Date",3))))

if (!inherits(D, "try-error")) {
    #Convert line list to an sts object
    sts <- linelist2sts(D, dateCol="dOnset", aggregate.by="1 day")

    #Plot the result
    plot(sts,xaxis.years=FALSE,legend.opts=NULL,xlab="time (days)")
}

Run the code above in your browser using DataLab