# Basic usage with single expression
# Build a quoted expression using mcnodes defined in mctable or built with
# mcstoc()/mcdata within the expression (do NOT set nvariates, it is
# inferred from nrow(data) when evaluated by eval_module()).
expr_example <- quote({
# Within-herd prevalence (assigned from a pre-built mcnode w_prev)
inf_a <- w_prev
# Estimate of clinic sensitivity
clinic_sensi <- mcstoc(runif, min = 0.6, max = 0.8)
# Probability an infected animal is tested in origin and not detected
false_neg_a <- inf_a * test_origin * (1 - test_sensi) * (1 - clinic_sensi)
# Probability an infected animal is not tested and not detected
no_test_a <- inf_a * (1 - test_origin) * (1 - clinic_sensi)
# no_detect_a: total probability an infected animal is not detected
no_detect_a <- false_neg_a + no_test_a
})
# Evaluate
eval_module(
exp = expr_example,
data = imports_data,
mctable = imports_mctable,
data_keys = imports_data_keys
)
Run the code above in your browser using DataLab