fit_multinom_dag: Inference in discrete Bayesian networks

Description Usage Arguments Value Examples

View source: R/sparsebnUtils-inference.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
### 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)

sparsebnUtils documentation built on Jan. 27, 2021, 9:05 a.m.