Learn R Programming

MoTBFs (version 2.0)

variableElimination: Exact inference

Description

Compute the posterior distribution of a variable of interest given some evidence. The variable elimination algorithm is used.

Usage

variableElimination(bn, target, evidence = NULL, elimOrder = NULL)

Value

The posterior probability distribution of the target variable as an object of class univmotbf or piecewisemop if target is continuous, or a matrix if target is discrete.

Arguments

bn

An object of class motbf_fit, obtained from function motbf.fit.

target

A character string equal to the name of the variable of interest.

evidence

A data.frame of one row containing the value of the observed variables. A list can also be provided.

elimOrder

The elimination order can be manually specified as a vector containing the names of the variables, in the desired order. If elimOrder is not specified, the topological order is computed.

Examples

Run this code
## Dataset
  data("ecoli", package = "MoTBFs")
  data <- ecoli[,-c(1,9)]

## Get directed acyclic graph
  dag <- LearningHC(data)
  
## Learn bayesian network
  bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP")
  
## Specify the evidence set and target variable
  obs <- data.frame(lip = "0.48", alm1 = 0.55, stringsAsFactors=FALSE)
  node <- "alm2" 
ve = variableElimination(bn, target = node, evidence = obs)

Run the code above in your browser using DataLab