Standardize a tidy input dataset.
hbl_data(
data,
response,
study,
study_reference,
group,
group_reference,
patient,
rep,
rep_reference,
covariates
)
A tidy data frame or tibble
with the data.
Character of length 1,
name of the column in data
with the response/outcome variable.
data[[response]]
must be a continuous variable,
and it should be the change from baseline of a
clinical endpoint of interest, as opposed to just
the raw response. Treatment differences
are computed directly from this scale, please supply
change from baseline unless you are absolutely certain
that treatment differences computed directly from
this quantity are clinically meaningful.
Character of length 1,
name of the column in data
with the study ID.
Atomic of length 1,
element of the study
column that indicates
the current study.
(The other studies are historical studies.)
Character of length 1,
name of the column in data
with the group ID.
Atomic of length 1,
element of the group
column that indicates
the control group.
(The other groups may be treatment groups.)
Character of length 1,
name of the column in data
with the patient ID.
Character of length 1,
name of the column in data
with the rep ID.
Atomic of length 1,
element of the rep
column that indicates
baseline, i.e. the first rep chronologically.
(The other reps may be post-baseline study visits or time points.)
Character vector of column names
in data
with the columns with baseline covariates.
These can be continuous, categorical, or binary.
Regardless, historicalborrowlong
derives the appropriate
model matrix.
Each baseline covariate column must truly be a baseline covariate: elements must be equal for all time points within each patient (after the steps in the "Data processing" section). In other words, covariates must not be time-varying.
A large number of covariates, or a large number of levels in a categorical covariate, can severely slow down the computation. Please consider carefully if you really need to include such complicated baseline covariates.
A standardized tidy data frame with one row per patient and the following columns:
response
: continuous response/outcome variable. (Should be
change from baseline of an outcome of interest.)
study_label
: human-readable label of the study.
study
: integer study index with the max index equal to the
current study (at study_reference
).
group_label
: human-readable group label (e.g. treatment arm name).
group
: integer group index with an index of 1 equal to the control
group (at group_reference
).
patient_label
: original patient ID.
patient
: integer patient index.
rep_label
: original rep ID (e.g. time point or patient visit).
rep
: integer rep index.
covariate_*
: baseline covariate columns.
Users do not normally need to call this function. It mainly serves exposes the indexing behavior of studies and group levels to aid in interpreting summary tables.
Before running the MCMC, dataset is pre-processed. This includes expanding the rows of the data so every rep of every patient gets an explicit row. So if your original data has irregular rep IDs, e.g. unscheduled visits in a clinical trial that few patients attend, please remove them before the analysis. Only the most common rep IDs should be added.
After expanding the rows, the function fills in missing values for every column except the response. That includes covariates. Missing covariate values are filled in, first with last observation carried forward, then with last observation carried backward. If there are still missing values after this process, the program throws an informative error.
set.seed(0)
data <- hbl_sim_independent(n_continuous = 1, n_study = 2)$data
data <- dplyr::select(
data,
study,
group,
rep,
patient,
response,
tidyselect::everything()
)
data <- dplyr::rename(
data,
change = response,
trial = study,
arm = group,
subject = patient,
visit = rep,
cov1 = covariate_study1_continuous1,
cov2 = covariate_study2_continuous1
)
data$trial <- paste0("trial", data$trial)
data$arm <- paste0("arm", data$arm)
data$subject <- paste0("subject", data$subject)
data$visit <- paste0("visit", data$visit)
hbl_data(
data = data,
response = "change",
study = "trial",
study_reference = "trial1",
group = "arm",
group_reference = "arm1",
patient = "subject",
rep = "visit",
rep_reference = "visit1",
covariates = c("cov1", "cov2")
)
#> # A tibble: 1,600 × 11
#> study patient patient_label rep rep_label response study_label group_label
#> <int> <int> <chr> <int> <chr> <dbl> <chr> <chr>
#> 1 1 4 subject101 1 visit1 0.753 trial2 arm1
#> 2 1 4 subject101 2 visit2 -1.43 trial2 arm1
#> 3 1 4 subject101 3 visit3 -2.02 trial2 arm1
#> 4 1 4 subject101 4 visit4 0.644 trial2 arm1
#> 5 1 5 subject102 1 visit1 1.38 trial2 arm1
#> 6 1 5 subject102 2 visit2 -2.63 trial2 arm1
#> 7 1 5 subject102 3 visit3 0.865 trial2 arm1
#> 8 1 5 subject102 4 visit4 0.262 trial2 arm1
#> 9 1 6 subject103 1 visit1 -0.791 trial2 arm1
#> 10 1 6 subject103 2 visit2 -2.09 trial2 arm1
#> # ℹ 1,590 more rows
#> # ℹ 3 more variables: group <int>, covariate_cov1 <dbl>, covariate_cov2 <dbl>