R Under development (unstable) (2024-02-11 r85891 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(pcalg) > > ## Tests whether "intervention matrices" can correctly be mapped to a > ## targets/target index pair, and vice versa > > nreps <- 30 > p <- 20 > n <- 200 > > for (i in 1:nreps) { + set.seed(i) + A <- matrix(as.logical(rbinom(n*p, 1, 0.01)), nrow = n, ncol = p) + + ## Testing conversion of matrix to list of targets + target.list <- mat2targets(A) + if (any(duplicated(target.list$targets))) + stop("Targets are not unique!") + for (j in 1:n) + if (!all.equal(which(A[j, ]), + target.list$targets[[target.list$target.index[j]]])) + stop("Targets not correctly represented!") + + ## Test back-conversion + B <- targets2mat(p, target.list$targets, target.list$target.index) + if (!identical(A, B)) + stop("Intervention matrix not correctly represented!") + } > > > proc.time() user system elapsed 1.81 0.20 2.00