getTimeSeriesLab separates original data into multiple time windows, and summarize statistical information.

getTimeSeriesLab(
  labData,
  idColName,
  labItemColName,
  dateColName,
  valueColName,
  indexDate = last,
  gapDate = NULL,
  completeWindows = TRUE
)

Arguments

labData

a file or dataframe of laboratory test data with at least 4 columns about patient ID, lab item, test value and test date, respectively.

idColName

the column name that records patient ID in labData.

labItemColName

the column name that records lab item in labData. If lab code is combined by multiple columns, then just simply add + operator between column names, e.g., A + B.

dateColName

the column name that records test date in labData. It should be in "YYYYMMDD"/"YYYY-MM-DD" format.

valueColName

the column name that records test value in labData. Only numeric value is acceptable.

indexDate

the specific date that used for cutting time window. It can be first record ("first"), last record ("last"), any single date of interest with "YYYYMMDD"/"YYYY-MM-DD" format, or (indexTable), with ID and indexDate mapping table.

gapDate

desired period (in days) of each window interval. If NULL, it will be seen as only one single time window.

completeWindows

logical. If TRUE, time window series will be complete in order. If FALSE, a window without lab test will be skipped. Default is TRUE.

Value

A data.table with statistical summary.

Details

This function is used for separating lab data into multiple time windows, and it provides overall statistical information: total count, maximun value, minimun value, mean, nearest record to index date of each time window. If indexDate is first, then it will be the earliest test date among all the lab tests.

Examples

ts<-getTimeSeriesLab(labData = labSample,
                idColName = SUBJECT_ID,
                labItemColName = ITEMID,
                dateColName = CHARTTIME,
                valueColName = VALUENUM,
                indexDate = last,
                gapDate = 360,
                completeWindows = TRUE)
head(ts)
#>    ID ITEMID Window Count  Max Min   Mean Nearest firstRecord lastRecode
#> 1: 36  50811     -4     4 12.7  10 11.675    12.7  2131-05-04 2131-05-18
#> 2: 36  50811     -3    NA   NA  NA     NA      NA        <NA>       <NA>
#> 3: 36  50811     -2    NA   NA  NA     NA      NA        <NA>       <NA>
#> 4: 36  50811     -1    NA   NA  NA     NA      NA        <NA>       <NA>
#> 5: 36  50861     -4     2 12.0   8 10.000    12.0  2131-04-30 2131-05-17
#> 6: 36  50861     -3    NA   NA  NA     NA      NA        <NA>       <NA>
head(indexTable)
#> # A tibble: 5 x 2
#>      ID indexDate 
#>   <int> <date>    
#> 1    36 2134-05-18
#> 2   109 2142-08-29
#> 3   132 2115-12-23
#> 4   143 2155-10-22
#> 5   145 2145-02-20
tsindex<-getTimeSeriesLab(labData = labSample,
                idColName = SUBJECT_ID,
                labItemColName = ITEMID,
                dateColName = CHARTTIME,
                valueColName = VALUENUM,
                indexDate = indexTable,
                gapDate = 360,
                completeWindows = TRUE)
head(tsindex)
#>    ID ITEMID Window Count  Max Min   Mean Nearest firstRecord lastRecode
#> 1: 36  50811     -4     4 12.7  10 11.675    12.7  2131-05-04 2131-05-18
#> 2: 36  50811     -3    NA   NA  NA     NA      NA        <NA>       <NA>
#> 3: 36  50811     -2    NA   NA  NA     NA      NA        <NA>       <NA>
#> 4: 36  50811     -1    NA   NA  NA     NA      NA        <NA>       <NA>
#> 5: 36  50811      1    NA   NA  NA     NA      NA        <NA>       <NA>
#> 6: 36  50861     -4     2 12.0   8 10.000    12.0  2131-04-30 2131-05-17