More or less an internal function that implements general marginalization algorithm of a compositional model.

generalMarginalization(this, varToRemove)

Arguments

this

compositional model

varToRemove

variable to remove from the model

Value

marginalized model

Examples

# load compositional model data(m) generalMarginalization
#> function (this, varToRemove) #> { #> whereIsVariable <- which(sapply(getVariables(this), function(x, #> y) { #> y %in% x #> }, varToRemove, simplify = TRUE)) #> toReplace <- list() #> K <- NULL #> oldDist <- Distribution("new") #> for (i in whereIsVariable) { #> pomDist <- getDistribution(this, i) #> K <- union(K, getVariables(pomDist)) #> Lik <- setdiff(K, varToRemove) #> suppressWarnings(oldDist <- anticipate(oldDist, pomDist, #> Lik)) #> marginalize(oldDist, varToRemove, keep = F, new = FALSE) #> toReplace <- c(toReplace, list(oldDist)) #> } #> replaceDistribution(this, whereIsVariable, toReplace) #> deleteEmptyDistributions(this) #> } #> <bytecode: 0x000000001331af20> #> <environment: namespace:mudim>