Learn R Programming

sparsebnUtils (version 0.0.8)

fit_multinom_dag: Inference in discrete Bayesian networks

Description

Given the structure of a Bayesian network, estimate the parameters using multinomial logistic regression. For each node \(i\), regress \(i\) onto its parents set using multinom in package nnet.

Usage

fit_multinom_dag(parents, dat)

Arguments

parents

An edgeList object.

dat

Data, a dataframe or matrix

Value

A list with with one component for each node in the graph. Each node is a coefficient matrix for the parents of that node.

Examples

Run this code
# NOT RUN {
### construct a random data set
x <- c(0,1,0,1,0)
y <- c(1,0,1,0,1)
z <- c(0,1,2,1,0)
a <- c(1,1,1,0,0)
b <- c(0,0,1,1,1)
dat <- data.frame(x, y, z, a, b)

### randomly construct an edgelist of a graph
nnode <- ncol(dat)
li <- vector("list", length = nnode)
li[[1]] <- c(2L,4L)
li[[2]] <- c(3L,4L,5L)
li[[3]] <- integer(0)
li[[4]] <- integer(0)
li[[5]] <- integer(0)
edgeL <- edgeList(li)

### run fit_multinom_dag
fit.multinom <- fit_multinom_dag(edgeL, dat)

# }

Run the code above in your browser using DataLab