Create a Subject History Table
Usage
CreateHistory(
rawData_ls,
personsTable = "everybody",
firstDay_int = NULL,
lastDay_int = NULL
)
Arguments
- rawData_ls
a list of tibbles returned by
loadRawData
- personsTable
What is the name of the data table that contains all the subject IDs? Defaults to
"everybody"
. If no such table exists, then set this value to"none"
and the unique subject IDs will be drawn from all tables inrawData_ls
- firstDay_int
(OPTIONAL) What should be the first "day" counter for all subjects? This may be beneficial to set if you wish to have the History ignore all days before a certain point.
- lastDay_int
(OPTIONAL) What should be the last "day" counter for all subjects?
Value
A tibble with columns who
and when
. Each subject will
have one row for each day in the study range.
Details
We may want to perform SQL-like operations on a set of tables. This data table will form the "backbone" for future join operations. It creates one record per person for each day in the study. The default behavior is to set the date range to the smallest observed value for "when" across all data tables to the largest observed value for "when" across all tables, inclusive. Necessarily, this is very sensitive to outliers or coding errors (for instance, if one subject has a "first day" 200 days before Study Day 0, then this History table will include days -200 to -1 for ALL subjects, regardless of any recorded contact in this period).
If this behavior is not desirable, you must specify a study range. For
example, you may have a short recruitment period followed by a 6-month
clinical trial. In this instance, you may want to ignore any data more
than 30 days prior to Study Day 0 for each subject or more than a few
weeks after the end of the trial. Thus, you would set
firstDay_int = -30L
and lastDay_int = 6 * 30 + 14
.
Examples
data_ls <- loadRawData(c("tlfb", "all_drugs", "everybody"))
CreateHistory(rawData_ls = data_ls, firstDay_int = -30)
#> # A tibble: 2,459,960 × 2
#> who when
#> <int> <dbl>
#> 1 8 -30
#> 2 8 -29
#> 3 8 -28
#> 4 8 -27
#> 5 8 -26
#> 6 8 -25
#> 7 8 -24
#> 8 8 -23
#> 9 8 -22
#> 10 8 -21
#> # ℹ 2,459,950 more rows