Skip to contents

Define an outcome variable for a causal_tbl

Usage

set_outcome(data, outcome)

get_outcome(data)

has_outcome(data)

pull_outcome(data)

Arguments

data

a data frame or causal_tbl

outcome

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

Value

A causal_tbl

For get_outcome() the column name of the outcome variable

For has_outcome(), TRUE if there is an outcome variable set

For pull_outcome(), the vector of the outcome 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_outcome(guess)
print(data) # a causal_tbl
#> # A <causal_tbl> [8 × 2]
#>              [out]
#>   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_outcome(data)
#> [1] "guess"