Learn R Programming

mcmodule (version 1.1.1)

at_least_one: Combined Probability of Events (At least one)

Description

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
)

Value

Updated mcmodule with new combined probability node

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)

Examples

Run this code
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")
print(module$node_list$p_combined$summary)

Run the code above in your browser using DataLab