The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

quantify()-ing binary outcomes

quantify() evaluates whether the top event occurs under each scenario. With the default prob = FALSE, inputs are binary (failed / not failed) for each basic event.

This vignette covers:

Setup: formulate the top event

library(tidyfault)
library(dplyr)
library(purrr)
library(tibble)

data("db_nodes")
data("db_edges")

f <- curate(db_nodes, db_edges) |>
  equate() |>
  formulate()
sort(names(formals(f)))
#> [1] "AF"  "AUF" "BF"  "DC"  "HF"  "MF"  "NF"  "SF"

Single scenario: direct function call

Any scenario can be passed as named arguments matching formals(f):

f(DC = 1, AF = 1, SF = 0, BF = 0, NF = 0, AUF = 0, HF = 0, MF = 0)
#> [1] 2

Many scenarios: quantify() on a data frame

Bundled db_outcomes_binary holds several rows of 0/1 inputs:

data("db_outcomes_binary")
head(db_outcomes_binary)
#> # A tibble: 6 × 9
#>   scenario    DC    AF    SF    BF    NF   AUF    HF    MF
#>      <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1        1     0     1     0     1     0     0     0     1
#> 2        2     0     0     1     0     1     0     0     1
#> 3        3     1     0     0     1     0     0     0     0
#> 4        4     0     1     0     0     1     0     1     0
#> 5        5     0     0     0     1     0     1     0     1
#> 6        6     1     0     0     0     1     0     0     1

quantify() returns one logical top-event outcome per row:

mybinary <- quantify(f, newdata = db_outcomes_binary)
mybinary
#>  [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE

Batch evaluation: IT security tree

For larger batches, build a tibble of draws (one column per basic event), then call quantify() once. The example below uses it_security_probs as Bernoulli parameters and fixes the seed for reproducibility.

data("it_security_nodes")
data("it_security_edges")
data("it_security_probs")

f_sec <- formulate(equate(curate(it_security_nodes, it_security_edges)))

set.seed(123)
n_binary <- 5000
batch_binary <- it_security_probs |>
  map(~ rbinom(n_binary, size = 1, prob = .x)) |>
  as_tibble()

outcomes_batch <- quantify(f_sec, newdata = batch_binary)
table(outcomes_batch)
#> outcomes_batch
#> FALSE  TRUE 
#>  4914    86
mean(outcomes_batch)
#> [1] 0.0172

Why vectorize?


Summary

Input quantify() usage
One scenario Named vector, list, or one-row data frame
Many scenarios Data frame / tibble with one column per basic event
Top event type Logical vector (TRUE = top event occurred)

For probabilities instead of 0/1 inputs, see quantify()-ing probabilities.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.