R Under development (unstable) (2024-02-05 r85863 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")) > .libPaths() [1] "D:/temp/RtmpUfjcaW/RLIBS_2f0785bf6de8" [2] "D:/RCompile/recent/R/library" > ## acyclic graphs > > nreps <- 30 > p <- 8 > n <- 1000 > > for(u2pd in c("rand", "retry", "relaxed")) { + cat("\n u2pd =", u2pd, "\n ------------\n") + cyc.res <- logical(nreps) + for (i in 1:nreps) { + set.seed(i) + myDAG <- randomDAG(p, prob = 0.2) + d.mat <- rmvDAG(n, myDAG, errDist = "normal") + res <- suppressWarnings(pcAlgo(d.mat, alpha = 0.05, directed=TRUE, u2pd = u2pd)) + ## ------ directed; u2pd = "rand" --> udag2pdag() + res.A <- wgtMatrix(res@graph) + res.A[res.A!=0] <- 1 + undir.A <- res.A + t(res.A) + undir.A[undir.A==1] <- 0 + undir.A[undir.A==2] <- 1 + res.dir <- res.A - undir.A + cyc.res[i] <- ggm::isAcyclic(res.dir) + } + if (!all(cyc.res)) stop("Test of pcAlgo(*, directed): Cyclic part in PDAG!") + } ## for(u2pd ...) u2pd = rand ------------ u2pd = retry ------------ u2pd = relaxed ------------ > cat('Time elapsed: ', (.pt <- proc.time()),"\n") Time elapsed: 2.2 0.2 2.39 NA NA > > ## find collider correctly > set.seed(123) > myDAG <- randomDAG(3, prob = 0.5) > library(Matrix) > as(myDAG,"sparseMatrix") 3 x 3 sparse Matrix of class "dgCMatrix" 1 2 3 1 . . 0.4680792 2 . . 0.9464206 3 . . . > d.mat <- rmvDAG(n, myDAG, errDist = "normal") > res <- pcAlgo(d.mat, alpha = 0.05, corMethod = "standard",directed=TRUE) Warning message: pcAlgo() is deprecated and only kept for backward compatibility. Please use skeleton, pc, or fci instead > gEst <- wgtMatrix(res@graph) > gTrue <- rbind(0,0, c(1,1,0)) > if(!all(gEst==gTrue)) stop("Test of udag2pdag: Problem finding a collider!") > > cat('Time elapsed: ', proc.time() - .pt,'\n') # "stats" Time elapsed: 0.58 0.03 0.61 NA NA > > > proc.time() user system elapsed 2.78 0.23 3.00