Skip to contents

Convert a dataset from raw response to change from baseline.

Usage

brm_data_change(data, name_change = "change", name_baseline = "baseline")

Arguments

data

A classed tibble (e.g. from brm_data()) with raw response as the outcome variable and no baseline time point stored in the attributes.

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

Examples

set.seed(0)
data <- brm_data(
  data = dplyr::rename(brm_simulate_simple()$data, y_values = response),
  outcome = "y_values",
  group = "group",
  time = "time",
  patient = "patient",
  reference_group = "group_1",
  reference_time = "time_1"
)
data
#> # A tibble: 800 × 4
#>    patient     time   y_values group  
#>    <chr>       <chr>     <dbl> <chr>  
#>  1 patient_001 time_1    1.47  group_1
#>  2 patient_001 time_2    3.10  group_1
#>  3 patient_001 time_3    2.22  group_1
#>  4 patient_001 time_4    0.215 group_1
#>  5 patient_002 time_1    1.03  group_1
#>  6 patient_002 time_2    2.28  group_1
#>  7 patient_002 time_3    2.36  group_1
#>  8 patient_002 time_4    2.33  group_1
#>  9 patient_003 time_1    0.128 group_1
#> 10 patient_003 time_2    1.89  group_1
#> # ℹ 790 more rows
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
#>    patient     time   group    delta baseline
#>    <chr>       <chr>  <chr>    <dbl>    <dbl>
#>  1 patient_001 time_2 group_1  1.63     1.47 
#>  2 patient_001 time_3 group_1  0.750    1.47 
#>  3 patient_001 time_4 group_1 -1.25     1.47 
#>  4 patient_002 time_2 group_1  1.25     1.03 
#>  5 patient_002 time_3 group_1  1.33     1.03 
#>  6 patient_002 time_4 group_1  1.29     1.03 
#>  7 patient_003 time_2 group_1  1.76     0.128
#>  8 patient_003 time_3 group_1  2.37     0.128
#>  9 patient_003 time_4 group_1  1.27     0.128
#> 10 patient_004 time_2 group_1  1.46     1.22 
#> # ℹ 590 more rows
attr(changed, "brm_outcome")
#> [1] "delta"
attr(changed, "brm_baseline")
#> [1] "baseline"
attr(data, "brm_reference_time")
#> [1] "time_1"