CPT: Estimate conditional probability tables

Description Usage Arguments Value Author(s) Examples

View source: R/CPT.R

Description

Estimates the conditional probability tables for bayesian network models, where the structure is given by an adjacency matrix.

Usage

1
CPT(adj_matrix, data, bayes_smooth = 0)

Arguments

adj_matrix

The adjacency matrix for the DAG.

data

The data the probabilities should be estimated from.

bayes_smooth

The additional cell counts for bayesian estimation of probability tables.

Value

A list of the conditional probability tables for the bayesian network. If the bayes_smooth argument is zero, it is the maximum likelihood estimates. Otherwise, it is bayesian estimates.

Author(s)

Katrine Kirkeby, enir_tak@hotmail.com

Maria Knudsen, mariaknudsen@hotmail.dk

Ninna Vihrs, ninnavihrs@hotmail.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
set.seed(43)
var1 <- c(sample(c(1, 2), 50, replace = TRUE))
var2 <- var1 + c(sample(c(1, 2), 50, replace = TRUE))
var3 <- var1 + c(sample(c(0, 1), 50, replace = TRUE,
                        prob = c(0.9, 0.1)))
var4 <- c(sample(c(1, 2), 50, replace = TRUE))

data <- data.frame("var1" = as.character(var1),
                   "var2" = as.character(var2),
                   "var3" = as.character(var3),
                   "var4" = as.character(var4))

adj_matrix_DAG <- matrix(c(0, 0, 0, 0,
                           1, 0, 0, 0,
                           1, 0, 0, 0,
                           0, 1, 0, 0),
                          nrow = 4)
                          
rownames(adj_matrix_DAG) <- colnames(adj_matrix_DAG) <- names(data)
                          
CPT(adj_matrix_DAG, data)
CPT(adj_matrix_DAG, data, bayes_smooth = 1)

nvihrs14/tcherry documentation built on Aug. 1, 2020, 6:25 p.m.