Learn R Programming

PCBN (version 0.1.1)

compute_sample_margin: Computes a conditional margin during sampling

Description

Computes a conditional margin during sampling

Usage

compute_sample_margin(
  object,
  data,
  v,
  cond_set,
  check_PCBN = TRUE,
  verbose = 1
)

Value

a vector of size \(n\) of realizations \(u_{i, v | cond\_set}\)

for \(i = 1, \dots, n\).

Arguments

object

PCBN object to sample from. This does not work if the PCBN does not abide by the B-sets. And in general, it does not work if the PCBN is outside of the class of restricted PCBNs.

data

data frame of observations of size n

v

name of the node

cond_set

conditioning set. This is a vector containing the names of all the nodes in the conditioning set.

check_PCBN

check whether the given PCBN satisfies the restrictions. If this is set to FALSE, no checking is performed. This means that the error due to the a non-restricted PCBN object (if this is the case) will occur later in the computations (and may not be so clear - typically it is because of failing to find a given conditional copula).

verbose

if 0, don't print anything. If verbose >= 1, print information about the fitting procedure.

Examples

Run this code

DAG = create_empty_DAG(3)
DAG = bnlearn::set.arc(DAG, 'U1', 'U3')
DAG = bnlearn::set.arc(DAG, 'U2', 'U3')

order_hash = r2r::hashmap()
order_hash[['U3']] = c("U1", "U2")

fam = matrix(c(0, 0, 1,
               0, 0, 1,
               0, 0, 0), byrow = TRUE, ncol = 3)
tau = 0.2 * fam

my_PCBN = new_PCBN(
  DAG, order_hash,
  copula_mat = list(tau = tau, fam = fam))

# Initialize data frame
N = 100
nodes = bnlearn::nodes(my_PCBN$DAG)
data = data.frame(matrix(ncol = length(nodes), nrow = N))
colnames(data) <- nodes

data[, "U1"] = stats::runif(N)
data[, "U2"] = stats::runif(N)
u_1_given2 = compute_sample_margin(object = my_PCBN, data = data,
                                   v = "U1", cond_set = c("U2"))

identical(data[, "U1"], u_1_given2)

Run the code above in your browser using DataLab