Convert Dates of Individual Case Reports into a Time Series of Counts
Convert Dates of Individual Case Reports into a Time Series of Counts
The function is used to convert an individual line list of cases to an aggregated time series of counts based on event date information of the cases.
latin1
linelist: A data.frame containing the line list of cases.
dateCol: A character string stating the column name in linelist which contains the event occurrence information (as a vector of Dates) 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 date for doing the aggregation. If not specified these dates are extracted automatically by taking range(D[,dateCol]) and adjust these according to aggregate.by (e.g. always first of a month).
epochInPeriodStr: strptime compatible format string to use for determining how a date is placed within the epoch. This is, e.g., used to move the dRange epochs to the beginning of the period. Example: In case of weekly aggregation the "%u" determines which day within the week (Monday is day 1) we have. See strptime for further details.
startYearFormat: strptime compatible format string to use for determining how the start entry of the sts object is generated. Usually the provided defaults are sufficient.
startEpochFormat: strptime compatible format string to use for determining how the start entry of the sts object is generated. Usually the provided defaults are sufficient.
Details
The date range is automatically extended such that the starting and ending dates are always the first epoch within the period, i.e. for aggregation by week it is moved to Mondays. This is controlled by the epochInPeriodStr parameter.
Please note that the formatting strings are implemented by the formatDate function, which uses strptime
formatting strings as well as formatting of quarters via "%Q", "%OQ" and "%q".
Returns
The function returns an object of class "sts". The freq slot might not be appropriate.
Author(s)
Michael
See Also
seq.Date, strptime, formatDate
Examples
#Load O104 outbreak datadata("husO104Hosp")#Convert line list to an sts objectsts <- linelist2sts(husO104Hosp, dateCol="dHosp", aggregate.by="1 day")#Check that the number of cases is correctall.equal(sum(observed(sts)),nrow(husO104Hosp))#Plot the resultplot(sts,xaxis.tickFreq=list("%d"=atChange,"%m"=atChange), xaxis.labelFreq=list("%d"=at2ndChange), xaxis.labelFormat="%d %b", xlab="",las=2,cex.axis=0.8)