marginalize.Rd
Having a probability distribution \(\pi(K)\), and a subset of variables \(L \subseteq K\), \(\pi^{\downarrow L}\) denotes a marginal distribution of \(\pi\) defined for each \(x \in X_L\) by the formula $$\pi^{\downarrow L}(x) = \sum_{y \in X_K; y^{\downarrow L} = x}\pi(y).$$ Note that we do not exclude situations when \(L = \emptyset\), for which we get \(\pi^{\downarrow \emptyset} = 1\).
In case of a compositional model, the marginalization is a complicated process.
marginalize(x, variables = NULL, keep = TRUE, new = TRUE, ...) # S3 method for Distribution marginalize(x, variables = NULL, keep = TRUE, new = TRUE, ...) # S3 method for Model marginalize(x, variables = NULL, keep = TRUE, perfect = FALSE, new = TRUE, ...)
x | Distribution, Compositional model |
---|---|
variables | vector of variables |
keep | logical, if |
new | logical, if TRUE a new distribution/compositional model is created. Otherwise the current one is changed. |
perfect | logical, if |
If input is:
Distribution return marginalized Distribution
Model return marginalized Model
To obtain the marginal distribution over a subset of random variables, one only needs to drop the irrelevant variables (the variables that one wants to marginalize out).
In case of having a compositional model, the situation is more complex and there are many approaches how to speed up the process.
Variables in variables
will be marginalized out if the keep
parameter will be FALSE
. In the opposite
case, variables in variables
will stay in Distribution. If the new
parameter is TRUE
then a new
Distribution is created and the original one stays unchanged. In the other case, the original distribution referenced
in parameter x
is changed and marginalized.
Distribution
: Marginalize probability distribution
Model
: Marginalize Compositional model
#> [1] "A" "B"#> A MUDIM.frequency #> 1: 0 0.3 #> 2: 1 0.7dTable(Pi)#> A B MUDIM.frequency #> 1: 0 0 0.1 #> 2: 0 1 0.2 #> 3: 1 0 0.3 #> 4: 1 1 0.4marginalize(Pi, variables = "A", new = FALSE)#> Probability distribution #> * Name:pi #> * Info: #> * Variables:A #> * Non-empty items:2 #> NULLdTable(Pi)#> A MUDIM.frequency #> 1: 0 0.3 #> 2: 1 0.7#> Compositional model #> * Name:demo model #> * Info:created for demonstration of the mudim package functionality #> * Variables:D, N, R, T, W, U, B #> * Length:7 #> NULLvariables(m)#> [1] "D" "N" "R" "T" "W" "U" "B"