Skip to contents

Combines probabilities of multiple events assuming independence, using the formula P(A or B) = 1 - (1-P(A))*(1-P(B)). It matches dimensions automatically.

Usage

at_least_one(
  mcmodule,
  mc_names,
  name = NULL,
  all_suffix = NULL,
  prefix = NULL,
  summary = TRUE
)

Arguments

mcmodule

Module containing node list and input data frames

mc_names

Vector of node names to combine

name

Optional custom name for combined node (default: NULL)

all_suffix

Suffix for combined node name (default: "all")

prefix

Optional prefix for output node name (default: NULL)

summary

Whether to calculate summary statistics (default: TRUE)

Value

Updated mcmodule with new combined probability node

Examples

module <- list(
  node_list = list(
    p1 = list(
      mcnode = mcstoc(runif,
        min = mcdata(c(0.1, 0.2, 0.3), type = "0", nvariates = 3),
        max = mcdata(c(0.2, 0.3, 0.4), type = "0", nvariates = 3),
        nvariates = 3
      ),
      data_name = "data_x",
      keys = c("category")
    ),
    p2 = list(
      mcnode = mcstoc(runif,
        min = mcdata(c(0.5, 0.6, 0.7), type = "0", nvariates = 3),
        max = mcdata(c(0.6, 0.7, 0.8), type = "0", nvariates = 3),
        nvariates = 3
      ),
      data_name = "data_y",
      keys = c("category")
    )
  ),
  data = list(
    data_x = data.frame(
      category = c("A", "B", "C"),
      scenario_id = c("0", "0", "0")
    ),
    data_y = data.frame(
      category = c("B", "B", "B"),
      scenario_id = c("0", "1", "2")
    )
  )
)

module <- at_least_one(module, c("p1", "p2"), name = "p_combined")
#> p1 prev dim: [1001, 1, 3], new dim: [1001, 1, 5], 0 null matches
#> p2 prev dim: [1001, 1, 3], new dim: [1001, 1, 5], 2 null matches
print(module$node_list$p_combined$summary)
#>      mc_name scenario_id category      mean         sd       Min      2.5%
#> 1 p_combined           0        A 0.1491116 0.02879645 0.1000217 0.1031230
#> 2 p_combined           0        B 0.6632784 0.02499801 0.6034675 0.6159164
#> 3 p_combined           0        C 0.3499510 0.02871474 0.3000104 0.3027019
#> 4 p_combined           1        B 0.7387655 0.02366101 0.6825085 0.6941183
#> 5 p_combined           2        B 0.8125573 0.02262975 0.7622558 0.7710237
#>         25%       50%       75%     97.5%       Max  nsv Na's
#> 1 0.1236943 0.1484803 0.1741846 0.1963494 0.1998955 1001    0
#> 2 0.6447058 0.6633223 0.6817710 0.7094008 0.7167370 1001    0
#> 3 0.3241776 0.3517681 0.3739251 0.3973875 0.3999062 1001    0
#> 4 0.7208637 0.7402874 0.7577584 0.7790421 0.7863647 1001    0
#> 5 0.7943139 0.8128350 0.8307268 0.8508712 0.8585983 1001    0