Skip to contents

Generates a binary outcome by summing effects, computing probabilities via the logistic function, and drawing binary outcomes.

Usage

add_binary_outcome(
  data,
  linear_col = "y_linear",
  prob_col = "y_prob",
  binary_col = "y_bin"
)

Arguments

data

A data frame containing effect columns prefixed with ".".

linear_col

Name of the column to store the summed linear predictor (default "y_linear").

prob_col

Name of the column to store probabilities (default "y_prob").

binary_col

Name of the column to store binary outcomes (default "y_bin").

Value

A tibble with added linear predictor, probability, and binary outcome columns.

Examples

df <- tibble::tibble(.beta = 0.5, .u = rnorm(5), .error = rnorm(5))
add_binary_outcome(df)
#> # A tibble: 5 × 6
#>   .beta       .u .error y_linear y_prob y_binary
#>   <dbl>    <dbl>  <dbl>    <dbl>  <dbl>    <int>
#> 1   0.5 -1.40     1.15    -0.900  0.289        0
#> 2   0.5  0.255   -1.82     0.755  0.680        1
#> 3   0.5 -2.44    -0.247   -1.94   0.126        0
#> 4   0.5 -0.00557 -0.244    0.494  0.621        1
#> 5   0.5  0.622   -0.283    1.12   0.754        0