Combines probabilities of multiple independent events using the formula: P(at least one) = 1 - (1-P(A)) * (1-P(B)) * ... Automatically matches dimensions and keys.
Usage
at_least_one(
mcmodule,
mc_names,
name = NULL,
all_suffix = NULL,
prefix = NULL,
summary = TRUE
)Arguments
- mcmodule
(mcmodule object). Module containing node list and data frames.
- mc_names
(character vector). Node names to combine.
- name
(character, optional). Custom name for combined node. If NULL, auto-generated. Default: NULL.
- all_suffix
(character). Suffix for auto-generated node name. Default: "all".
- prefix
(character, optional). Prefix for output node name. Default: NULL.
- summary
(logical). If TRUE, calculate summary statistics. Default: TRUE.
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.1505140 0.02899100 0.1002492 0.1026502
#> 2 p_combined 0 B 0.6635699 0.02486153 0.6028090 0.6155844
#> 3 p_combined 0 C 0.3491116 0.02879645 0.3000217 0.3031230
#> 4 p_combined 1 B 0.7373885 0.02388077 0.6813182 0.6911902
#> 5 p_combined 2 B 0.8129693 0.02314704 0.7632332 0.7710111
#> 25% 50% 75% 97.5% Max nsv Na's
#> 1 0.1253312 0.1495991 0.1757407 0.1975117 0.1999652 1001 0
#> 2 0.6453241 0.6649468 0.6819153 0.7077436 0.7190322 1001 0
#> 3 0.3236943 0.3484803 0.3741846 0.3963494 0.3998955 1001 0
#> 4 0.7195853 0.7380486 0.7561637 0.7782167 0.7861076 1001 0
#> 5 0.7942122 0.8122396 0.8332550 0.8514538 0.8572056 1001 0
