add_noise_to_outcomes: Add noise to match outcomes

Description Usage Arguments Details Value Examples

View source: R/add_noise_to_outcomes.R

Description

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.

Usage

1
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

Details

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

Value

a numeric vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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)

# Test different noise levels
test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 0.1)
table(test_df)

test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 0.5)
table(test_df)

test_df$noisy_outcome = add_noise_to_outcomes(test_df$true_outcome, error_prob = 1)
table(test_df)

dclaz/mELO documentation built on May 17, 2021, 2:27 a.m.