This function can be used to flip a set proportion of match outcomes. Useful for testing models under varying levels of signal to noise ratios.

add_noise_to_outcomes(outcome, error_prob = 0.1)

Arguments

outcome

Original match outcome. Must be one of 0, 0.5, or 1.

error_prob

The probability an outcome switches from a 0 to 1 or vice-versa

Value

a numeric vector.

Details

Input outcomes of 0.5 will be randomy rounded to either 0 or 1.

Examples

# Create some sample outcomes set.seed(1) test_df <- data.frame( true_outcome = sample(c(0,1), 1000, replace=TRUE) ) # No noise test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 0) table(test_df)
#> noisy_outcome #> true_outcome 0 1 #> 0 502 0 #> 1 0 498
# Test different noise levels test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 0.1) table(test_df)
#> noisy_outcome #> true_outcome 0 1 #> 0 450 52 #> 1 47 451
test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 0.5) table(test_df)
#> noisy_outcome #> true_outcome 0 1 #> 0 256 246 #> 1 228 270
test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 1) table(test_df)
#> noisy_outcome #> true_outcome 0 1 #> 0 0 502 #> 1 498 0