Convert a dataset from raw response to change from baseline.
Arguments
- data
A classed
tibble
(e.g. frombrm_data()
) with raw response as the outcome variable (role ="response"
inbrm_data()
).- name_change
Character of length 1, name of the new outcome column for change from baseline.
- name_baseline
Character of length 1, name of the new column for the original baseline response.
Value
A classed tibble
with change from baseline as the outcome variable
and the internal attributes modified accordingly. A special baseline
column is also created, and the original raw response column is removed.
The new baseline column is comprised of the elements of the response
variable corresponding to the reference_time
argument of brm_data()
.
If there is a column to denote missing values for simulation purposes,
e.g. the "missing"
column generated by brm_simulate_outline()
,
then missing baseline values are propagated accordingly such that
change from baseline will be missing if either the post-baseline response
is missing or the baseline response is missing.
See also
Other data:
brm_data()
Examples
set.seed(0)
data <- brm_data(
data = dplyr::rename(brm_simulate_simple()$data, y_values = response),
outcome = "y_values",
role = "response",
group = "group",
time = "time",
patient = "patient",
reference_group = "group_1",
reference_time = "time_1"
)
data
#> # A tibble: 800 × 4
#> y_values group time patient
#> <dbl> <chr> <chr> <chr>
#> 1 1.47 group_1 time_1 patient_001
#> 2 3.10 group_1 time_2 patient_001
#> 3 2.22 group_1 time_3 patient_001
#> 4 0.215 group_1 time_4 patient_001
#> 5 1.03 group_1 time_1 patient_002
#> 6 2.28 group_1 time_2 patient_002
#> 7 2.36 group_1 time_3 patient_002
#> 8 2.33 group_1 time_4 patient_002
#> 9 0.128 group_1 time_1 patient_003
#> 10 1.89 group_1 time_2 patient_003
#> # ℹ 790 more rows
attr(data, "brm_role")
#> [1] "response"
attr(data, "brm_outcome")
#> [1] "y_values"
attr(data, "brm_baseline")
#> NULL
attr(data, "brm_reference_time")
#> [1] "time_1"
changed <- brm_data_change(data = data, name_change = "delta")
changed
#> # A tibble: 600 × 5
#> delta baseline group time patient
#> <dbl> <dbl> <chr> <chr> <chr>
#> 1 1.63 1.47 group_1 time_2 patient_001
#> 2 0.750 1.47 group_1 time_3 patient_001
#> 3 -1.25 1.47 group_1 time_4 patient_001
#> 4 1.25 1.03 group_1 time_2 patient_002
#> 5 1.33 1.03 group_1 time_3 patient_002
#> 6 1.29 1.03 group_1 time_4 patient_002
#> 7 1.76 0.128 group_1 time_2 patient_003
#> 8 2.37 0.128 group_1 time_3 patient_003
#> 9 1.27 0.128 group_1 time_4 patient_003
#> 10 1.46 1.22 group_1 time_2 patient_004
#> # ℹ 590 more rows
attr(changed, "brm_role")
#> [1] "change"
attr(changed, "brm_outcome")
#> [1] "delta"
attr(changed, "brm_baseline")
#> [1] "baseline"
attr(data, "brm_reference_time")
#> [1] "time_1"