Skip to contents

Compare Probability of an Event with Benchmark

Usage

benchmark_event(
  data,
  column,
  benchmark,
  event,
  count,
  total,
  event_type = "",
  remove_missing = TRUE,
  notes = "minimal",
  input = "long",
  output = "console"
)

Arguments

data

dataset

column

name of column

benchmark

benchmark

event

specify event as given in column (example: 0, "pass", "success")

count

number of times event has occurred. Use only when using input = "values"

total

total number of all events. Use only when using input = "values"

event_type

Optional: a string describing the type of event. For example, success, failure, etc.

remove_missing

TRUE/FALSE (Default is TRUE)

notes

whether output should contain minimal or technical type of notes. Defaults to "minimal". Use "none" to turn off.

input

Default: "long" - long form of data, "values" to pass values directly. If using this option, must specify count and total.

output

Default: "console" - prints output in console and returns tibble invisibly.

Value

Dataframe of results when saved to an object. Show console output by default

Examples

data <- data.frame(task_1 = c("y", "y", "y", "y", "n", "n", "n", NA, NA, NA, NA, NA, NA, NA),
                   task_2 = c(0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1))
# With dataframe columns

benchmark_event(data, column = task_1, benchmark = 0.8, event = "y")
#> 
#> ── Compare Event Rate with a Benchmark ─────────────────────────────────────────
#> Based on the event rate of 58%, the probability that this rate exceeds a
#> benchmark of 80% is 3%
#>   term            result  
#>   count                4  
#>   total                7  
#>   benchmark          0.8  
#>   result        0.033344  
#>   probability      0.033  
benchmark_event(data, column = task_2, benchmark = 0.3, event = 1, event_type = "success")
#> 
#> ── Compare Event Rate with a Benchmark ─────────────────────────────────────────
#> Based on the success rate of 42%, the probability that this rate exceeds a
#> benchmark of 30% is 78%
#>   term             result  
#>   count                 6  
#>   total                14  
#>   benchmark           0.3  
#>   result        0.7805158  
#>   probability       0.781  

# Also pipeable
data |>
  benchmark_event(column = task_2, benchmark = 0.3, event = 1, event_type = "success")
#> 
#> ── Compare Event Rate with a Benchmark ─────────────────────────────────────────
#> Based on the success rate of 42%, the probability that this rate exceeds a
#> benchmark of 30% is 78%
#>   term             result  
#>   count                 6  
#>   total                14  
#>   benchmark           0.3  
#>   result        0.7805158  
#>   probability       0.781  

# With direct values
benchmark_event(benchmark = 0.8, count = 4, total = 7, input = "values")
#> 
#> ── Compare Event Rate with a Benchmark ─────────────────────────────────────────
#> Based on the event rate of 58%, the probability that this rate exceeds a
#> benchmark of 80% is 3%
#>   term            result  
#>   count                4  
#>   total                7  
#>   benchmark          0.8  
#>   result        0.033344  
#>   probability      0.033