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) > suppressWarnings(RNGversion("3.5.0")) > ################################################## > ## pcAlgo object > ################################################## > ## Load predefined data > data(gmG) > n <- nrow (gmG8$x) > V <- colnames(gmG8$x) > > ## define sufficient statistics > suffStat <- list(C = cor(gmG8$x), n = n) > ## estimate CPDAG > skel.fit <- skeleton(suffStat, indepTest = gaussCItest, + alpha = 0.01, labels = V) > (amSkel <- as(skel.fit, "amat")) Adjacency Matrix 'amat' (8 x 8) of type 'cpdag': Author Bar Ctrl Goal V5 V6 V7 V8 Author . 1 . . . 1 . 1 Bar 1 . 1 . 1 . . . Ctrl . 1 . . . . . . Goal . . . . . . . . V5 . 1 . . . 1 . 1 V6 1 . . . 1 . 1 . V7 . . . . . 1 . . V8 1 . . . 1 . . . > str(amSkel) 'amat' num [1:8, 1:8] 0 1 0 0 0 1 0 1 1 0 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:8] "Author" "Bar" "Ctrl" "Goal" ... ..$ : chr [1:8] "Author" "Bar" "Ctrl" "Goal" ... - attr(*, "type")= chr "cpdag" > stopifnot(attr(amSkel, "type") == "cpdag", + amSkel["Author", "Bar"] == 1, + amSkel["Bar", "Author"] == 1, + amSkel["Ctrl","Author"] == 0) > > pc.fit <- pc(suffStat, indepTest = gaussCItest, + alpha = 0.01, labels = V) > (amPC <- as(pc.fit, "amat")) Adjacency Matrix 'amat' (8 x 8) of type 'cpdag': Author Bar Ctrl Goal V5 V6 V7 V8 Author . 1 . . . . . . Bar 1 . 1 . . . . . Ctrl . 1 . . . . . . Goal . . . . . . . . V5 . 1 . . . . . . V6 1 . . . 1 . . . V7 . . . . . 1 . . V8 1 . . . 1 . . . > stopifnot(attr(amPC, "type") == "cpdag", + amPC["V5", "V8"] == 0, + amPC["V8", "V5"] == 1, + amPC["Goal","Author"] == 0) > > ################################################## > ## fciAlgo object > ################################################## > set.seed(42) > p <- 7 > ## generate and draw random DAG : > myDAG <- randomDAG(p, prob = 0.4) > > ## find PAG using the FCI algorithm > myC <- cov2cor(trueCov(myDAG)) > suffStat <- list(C = myC, n = 10^9) > V <- LETTERS[1:p] ## labels of nodes > > fmFCI <- fci(suffStat, indepTest=gaussCItest, labels = V, + alpha = 0.9999, doPdsep = FALSE) > (amFCI <- as(fmFCI, "amat")) Adjacency Matrix 'amat' (7 x 7) of type 'pag': A B C D E F G A . . 1 . 2 2 2 B . . . . 2 2 2 C 1 . . 1 2 2 2 D . . 1 . . 2 . E 1 1 1 . . . 2 F 1 1 1 1 . . 2 G 3 3 3 . 1 3 . > stopifnot(attr(amFCI, "type") == "pag", + amFCI["B","E"] == 2, + amFCI["C","D"] == 1, + amFCI["G","A"] == 3) > > proc.time() user system elapsed 1.64 0.28 1.92