Skip to contents

Define a treatment variable for a causal_tbl

Usage

set_treatment(data, treatment, outcome = get_outcome())

get_treatment(data)

has_treatment(data)

pull_treatment(data)

Arguments

data

a data frame or causal_tbl

treatment

the column containing the treatment variable (tidy-selected). Must be numeric or coercible to numeric.

outcome

the column containing the corresponding outcome variable (tidy-selected). Default is get_outcome()

Value

A causal_tbl

For get_treatment() the column name of the treatment variable. If an outcome variable has been set, the output name() will be the outcome column.

For has_treatment(), TRUE if there is a treatment variable set

For pull_treatment(), the vector of the treatment variable.

Examples

data <- data.frame(
  milk_first = c(0, 1, 0, 1, 1, 0, 0, 1),
  guess = c(0, 1, 0, 1, 1, 0, 0, 1)
) |>
  set_treatment(milk_first)
print(data) # a causal_tbl
#> # A <causal_tbl> [8 × 2]
#>        [trt]      
#>   milk_first guess
#>        <dbl> <dbl>
#> 1          0     0
#> 2          1     1
#> 3          0     0
#> 4          1     1
#> 5          1     1
#> 6          0     0
#> 7          0     0
#> 8          1     1
get_treatment(data)
#> [1] "milk_first"