
Derive LOCF (Last Observation Carried Forward) Records
Source:R/derive_locf_records.R
derive_locf_records.RdAdds LOCF records as new observations for each 'by group' when the dataset does not contain observations for missed visits/time points.
Arguments
- dataset
Input dataset
The columns specified by the
by_varsand theorderparameter are expected.- dataset_expected_obs
Expected observations dataset
Data frame with all the combinations of
PARAMCD,PARAM,AVISIT,AVISITN, ... which are expected in the dataset is expected.- by_vars
Grouping variables
For each group defined by
by_varsthose observations fromdataset_expected_obsare added to the output dataset which do not have a corresponding observation in the input dataset or for whichAVALis NA for the corresponding observation in the input dataset. Only variables specified inby_varswill be populated in the newly created records.- order
List of variables for sorting a dataset
The dataset is sorted by
orderbefore carrying the last observation forward (eg.AVAL) within eachby_vars.
Value
The input dataset with the new "LOCF" observations added for each
by_vars. Note, a variable will only be populated in the new parameter rows
if it is specified in by_vars.
Details
For each group (with respect to the variables specified for the by_vars parameter) those observations from dataset_expected_obs are added to the output dataset
which do not have a corresponding observation in the input dataset or
for which
AVALis NA for the corresponding observation in the input dataset.For the new observations,
AVALis set to the non-missingAVALof the previous observation in the input dataset (when sorted byorder) andDTYPEis set to "LOCF".
See also
BDS-Findings Functions for adding Parameters/Records:
default_qtc_paramcd(),
derive_extreme_records(),
derive_param_bmi(),
derive_param_bsa(),
derive_param_computed(),
derive_param_doseint(),
derive_param_exist_flag(),
derive_param_exposure(),
derive_param_extreme_event(),
derive_param_framingham(),
derive_param_map(),
derive_param_qtc(),
derive_param_rr(),
derive_param_wbc_abs(),
derive_summary_records()
Examples
library(dplyr)
library(tibble)
advs <- tribble(
~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~AVISITN, ~AVISIT,
"CDISC01", "01-701-1015", "PULSE", 61, 0, "BASELINE",
"CDISC01", "01-701-1015", "PULSE", 60, 2, "WEEK 6",
"CDISC01", "01-701-1015", "DIABP", 51, 0, "BASELINE",
"CDISC01", "01-701-1015", "DIABP", 50, 2, "WEEK 2",
"CDISC01", "01-701-1015", "DIABP", 51, 4, "WEEK 4",
"CDISC01", "01-701-1015", "DIABP", 50, 6, "WEEK 6",
"CDISC01", "01-701-1015", "SYSBP", 121, 0, "BASELINE",
"CDISC01", "01-701-1015", "SYSBP", 121, 2, "WEEK 2",
"CDISC01", "01-701-1015", "SYSBP", 121, 4, "WEEK 4",
"CDISC01", "01-701-1015", "SYSBP", 121, 6, "WEEK 6",
"CDISC01", "01-701-1028", "PULSE", 65, 0, "BASELINE",
"CDISC01", "01-701-1028", "DIABP", 79, 0, "BASELINE",
"CDISC01", "01-701-1028", "DIABP", 80, 2, "WEEK 2",
"CDISC01", "01-701-1028", "DIABP", NA, 4, "WEEK 4",
"CDISC01", "01-701-1028", "DIABP", NA, 6, "WEEK 6",
"CDISC01", "01-701-1028", "SYSBP", 130, 0, "BASELINE",
"CDISC01", "01-701-1028", "SYSBP", 132, 2, "WEEK 2"
)
# A dataset with all the combinations of PARAMCD, PARAM, AVISIT, AVISITN, ... which are expected.
advs_expected_obsv <- tibble::tribble(
~PARAMCD, ~AVISITN, ~AVISIT,
"PULSE", 0, "BASELINE",
"PULSE", 6, "WEEK 6",
"DIABP", 0, "BASELINE",
"DIABP", 2, "WEEK 2",
"DIABP", 4, "WEEK 4",
"DIABP", 6, "WEEK 6",
"SYSBP", 0, "BASELINE",
"SYSBP", 2, "WEEK 2",
"SYSBP", 4, "WEEK 4",
"SYSBP", 6, "WEEK 6"
)
derive_locf_records(
data = advs,
dataset_expected_obs = advs_expected_obsv,
by_vars = vars(STUDYID, USUBJID, PARAMCD),
order = vars(AVISITN, AVISIT)
)
#> # A tibble: 23 x 7
#> STUDYID USUBJID PARAMCD AVAL AVISITN AVISIT DTYPE
#> <chr> <chr> <chr> <dbl> <dbl> <chr> <chr>
#> 1 CDISC01 01-701-1015 DIABP 51 0 BASELINE NA
#> 2 CDISC01 01-701-1015 DIABP 50 2 WEEK 2 NA
#> 3 CDISC01 01-701-1015 DIABP 51 4 WEEK 4 NA
#> 4 CDISC01 01-701-1015 DIABP 50 6 WEEK 6 NA
#> 5 CDISC01 01-701-1015 PULSE 61 0 BASELINE NA
#> 6 CDISC01 01-701-1015 PULSE 60 2 WEEK 6 NA
#> 7 CDISC01 01-701-1015 PULSE 60 6 WEEK 6 LOCF
#> 8 CDISC01 01-701-1015 SYSBP 121 0 BASELINE NA
#> 9 CDISC01 01-701-1015 SYSBP 121 2 WEEK 2 NA
#> 10 CDISC01 01-701-1015 SYSBP 121 4 WEEK 4 NA
#> # … with 13 more rows