R Under development (unstable) (2024-09-06 r87103 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) > ## source("/u/kalischm/research/packages/LINGAM/R/lingamFuns.R") > > ##--> showProc.time(), assertError(), relErrV(), ... > R.home(); sessionInfo() # helping package maintainers to debug ... [1] "D:/RCompile/recent/R" R Under development (unstable) (2024-09-06 r87103 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: [1] LC_COLLATE=C LC_CTYPE=German_Germany.utf8 [3] LC_MONETARY=C LC_NUMERIC=C [5] LC_TIME=C time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] pcalg_2.7-12 loaded via a namespace (and not attached): [1] graph_1.82.0 igraph_2.0.3 DEoptimR_1.1-3 [4] clue_0.3-65 magrittr_2.0.3 fastICA_1.2-5.1 [7] abind_1.4-5 BiocGenerics_0.50.0 pkgconfig_2.0.3 [10] stats4_4.5.0 lifecycle_1.0.4 cli_3.6.3 [13] sfsmisc_1.1-19 ggm_2.5.1 corpcor_1.6.10 [16] robustbase_0.99-4 compiler_4.5.0 RBGL_1.80.0 [19] tools_4.5.0 cluster_2.1.6 bdsmatrix_1.3-7 [22] Rcpp_1.0.13 BiocManager_1.30.25 rlang_1.1.4 > .libPaths() [1] "D:/temp/Rtmp8cLpRq/RLIBS_76c4389f364" [2] "D:/RCompile/recent/R/library" > packageDescription("pcalg") Package: pcalg Version: 2.7-12 Date: 2024-09-05 Title: Methods for Graphical Models and Causal Inference Description: Functions for causal structure learning and causal inference using graphical models. The main algorithms for causal structure learning are PC (for observational data without hidden variables), FCI and RFCI (for observational data with hidden variables), and GIES (for a mix of data from observational studies (i.e. observational data) and data from experiments involving interventions (i.e. interventional data) without hidden variables). For causal inference the IDA algorithm, the Generalized Backdoor Criterion (GBC), the Generalized Adjustment Criterion (GAC) and some related functions are implemented. Functions for incorporating background knowledge are provided. Maintainer: Markus Kalisch Authors@R: c(person("Markus","Kalisch", email="kalisch@stat.math.ethz.ch", role=c("aut","cre")), person("Alain", "Hauser", role="aut"), person("Martin","Maechler", role="aut"), person("Diego", "Colombo", role="ctb"), person("Doris", "Entner", role="ctb"), person("Patrik", "Hoyer", role="ctb"), person("Antti", "Hyttinen", role="ctb"), person("Jonas", "Peters", role="ctb"), person("Nicoletta", "Andri", role="ctb"), person("Emilija", "Perkovic", role="ctb"), person("Preetam", "Nandy", role="ctb"), person("Philipp", "Ruetimann", role="ctb"),person("Daniel", "Stekhoven", role="ctb"), person("Manuel", "Schuerch", role="ctb"), person("Marco", "Eigenmann", role="ctb"), person("Leonard", "Henckel", role = "ctb"),person("Joris", "Mooij", role = "ctb")) Depends: R (>= 3.5.0) LinkingTo: Rcpp (>= 0.11.0), RcppArmadillo, BH Imports: stats, graphics, utils, methods, abind, graph, RBGL, igraph, ggm, corpcor, robustbase, vcd, Rcpp, bdsmatrix, sfsmisc (>= 1.0-26), fastICA, clue Suggests: MASS, Matrix, Rgraphviz, mvtnorm, huge, ggplot2, dagitty NeedsCompilation: yes Encoding: UTF-8 License: GPL (>= 2) URL: https://pcalg.r-forge.r-project.org/ Packaged: 2024-09-05 16:53:13 UTC; kalischm Author: Markus Kalisch [aut, cre], Alain Hauser [aut], Martin Maechler [aut], Diego Colombo [ctb], Doris Entner [ctb], Patrik Hoyer [ctb], Antti Hyttinen [ctb], Jonas Peters [ctb], Nicoletta Andri [ctb], Emilija Perkovic [ctb], Preetam Nandy [ctb], Philipp Ruetimann [ctb], Daniel Stekhoven [ctb], Manuel Schuerch [ctb], Marco Eigenmann [ctb], Leonard Henckel [ctb], Joris Mooij [ctb] Built: R 4.5.0; x86_64-w64-mingw32; 2024-09-06 18:05:04 UTC; windows Archs: x64 -- File: D:/RCompile/CRANincoming/R-devel/lib/pcalg/Meta/package.rds > packageDescription("Matrix") Package: Matrix Version: 1.7-0 VersionNote: do also bump src/version.h, inst/include/Matrix/version.h Date: 2024-03-16 Priority: recommended Title: Sparse and Dense Matrix Classes and Methods Description: A rich hierarchy of sparse and dense matrix classes, including general, symmetric, triangular, and diagonal matrices with numeric, logical, or pattern entries. Efficient methods for operating on such matrices, often wrapping the 'BLAS', 'LAPACK', and 'SuiteSparse' libraries. License: GPL (>= 2) | file LICENCE URL: https://Matrix.R-forge.R-project.org BugReports: https://R-forge.R-project.org/tracker/?atid=294&group_id=61 Contact: Matrix-authors@R-project.org Authors@R: c(person("Douglas", "Bates", role = "aut", comment = c(ORCID = "0000-0001-8316-9503")), person("Martin", "Maechler", role = c("aut", "cre"), email = "mmaechler+Matrix@gmail.com", comment = c(ORCID = "0000-0002-8685-9910")), person("Mikael", "Jagan", role = "aut", comment = c(ORCID = "0000-0002-3542-2938")), person("Timothy A.", "Davis", role = "ctb", comment = c(ORCID = "0000-0001-7614-6899", "SuiteSparse libraries", "collaborators listed in dir(system.file(\"doc\", \"SuiteSparse\", package=\"Matrix\"), pattern=\"License\", full.names=TRUE, recursive=TRUE)")), person("George", "Karypis", role = "ctb", comment = c(ORCID = "0000-0003-2753-1437", "METIS library", "Copyright: Regents of the University of Minnesota")), person("Jason", "Riedy", role = "ctb", comment = c(ORCID = "0000-0002-4345-4200", "GNU Octave's condest() and onenormest()", "Copyright: Regents of the University of California")), person("Jens", "Oehlschlägel", role = "ctb", comment = "initial nearPD()"), person("R Core Team", role = "ctb", comment = "base R's matrix implementation")) Depends: R (>= 4.4.0), methods Imports: grDevices, graphics, grid, lattice, stats, utils Suggests: MASS, datasets, sfsmisc, tools Enhances: SparseM, graph LazyData: no LazyDataNote: not possible, since we use data/*.R and our S4 classes BuildResaveData: no Encoding: UTF-8 NeedsCompilation: yes Packaged: 2024-03-19 17:15:14 UTC; maechler Author: Douglas Bates [aut] (), Martin Maechler [aut, cre] (), Mikael Jagan [aut] (), Timothy A. Davis [ctb] (, SuiteSparse libraries, collaborators listed in dir(system.file("doc", "SuiteSparse", package="Matrix"), pattern="License", full.names=TRUE, recursive=TRUE)), George Karypis [ctb] (, METIS library, Copyright: Regents of the University of Minnesota), Jason Riedy [ctb] (, GNU Octave's condest() and onenormest(), Copyright: Regents of the University of California), Jens Oehlschlägel [ctb] (initial nearPD()), R Core Team [ctb] (base R's matrix implementation) Maintainer: Martin Maechler Repository: CRAN Date/Publication: 2024-04-26 12:03:02 UTC Built: R 4.5.0; x86_64-w64-mingw32; 2024-09-06 11:30:30 UTC; windows Archs: x64 -- File: D:/temp/Rtmp8cLpRq/RLIBS_76c4389f364/Matrix/Meta/package.rds > cat("doExtras:", (doExtras <- pcalg:::doExtras()), "\n") doExtras: FALSE > > > ################################################## > ## Exp 1 > ################################################## > set.seed(123) > n <- 500 > eps1 <- sign(rnorm(n)) * sqrt(abs(rnorm(n))) > eps2 <- runif(n) - 0.5 # ~ U[-1/2, 1/2] > > X <- cbind(A = eps1 + 0.9*eps2, + B = eps2) > > ## x1 <- x2 > ## adjacency matrix: > ## 0 0 > ## 1 0 > (trueDAG <- rbind(c(0,0), + c(1,0))) [,1] [,2] [1,] 0 0 [2,] 1 0 > > estDAG <- LINGAM(X, verbose = TRUE) Performing row permutation, nzdiag*() ... (Small dimensionality, using brute-force method.): Done! Performing permutation for causal order... (Small dimensionality, using brute-force method.): Done! [,1] [,2] [1,] 0.0000000 0.001722255 [2,] 0.8506492 0.000000000 Causal B nicely triangular. No problems to report here. Pruning the network connections... Done! Warning message: In LINGAM(X, verbose = TRUE) : 'LINGAM' is deprecated. Use 'lingam' instead. See help("Deprecated") > > stopifnot(identical(estDAG, LINGAM(X)), + as.integer(estDAG$ Adj) == trueDAG, + all.equal (estDAG$ B, cbind(0, c(0.878188262685122, 0)))) Warning message: In LINGAM(X) : 'LINGAM' is deprecated. Use 'lingam' instead. See help("Deprecated") > > if(doExtras) { + ## using pcalg + n <- nrow(X) + V <- LETTERS[1:ncol(X)] # labels aka node names + + ## estimate CPDAG + pc.fit <- pc(suffStat = list(C = cor(X), n = n), + indepTest = gaussCItest, ## indep.test: partial correlations + alpha = 0.01, labels = colnames(X)) + if (require(Rgraphviz)) { + plot(pc.fit, main = "Estimated CPDAG") + } + } > > ################################################## > ## Exp 2 > ################################################## > set.seed(123) > n <- 500 > eps1 <- sign(rnorm(n)) * sqrt(abs(rnorm(n))) > eps2 <- runif(n) - 0.5 > eps3 <- sign(rnorm(n)) * abs(rnorm(n))^(1/3) > eps4 <- rnorm(n)^2 > > x1 <- eps1 + 0.9*eps2 > x2 <- eps2 > x3 <- 0.8*eps2 + eps3 > x4 <- -0.9*x3 - x1 + eps4 > > X <- cbind(U = x1, V = x2, W = x3, Y = x4) > > trueDAG <- cbind(c(0,1,0,0),c(0,0,0,0),c(0,1,0,0),c(1,0,1,0)) > ## x4 <- x3 <- x2 -> x1 -> x4 > ## adjacency matrix: > ## 0 0 0 1 > ## 1 0 1 0 > ## 0 0 0 1 > ## 0 0 0 0 > > estDAG <- LINGAM(X, verbose = TRUE) Performing row permutation, nzdiag*() ... (Small dimensionality, using brute-force method.): Done! Performing permutation for causal order... (Small dimensionality, using brute-force method.): Done! [,1] [,2] [,3] [,4] [1,] 0.00000000 0.01185382 0.009724318 0.010054538 [2,] 0.89993102 0.00000000 -0.037587250 0.003634021 [3,] 0.94576470 -0.04663875 0.000000000 0.018116176 [4,] -0.05985199 -0.88907479 -1.057332765 0.000000000 Causal B nicely triangular. No problems to report here. Pruning the network connections... Done! Warning message: In LINGAM(X, verbose = TRUE) : 'LINGAM' is deprecated. Use 'lingam' instead. See help("Deprecated") > > B.est <- rbind(c(0, 0.986119553, 0, 0), + c(0, 0, 0, 0), + c(0, 0.89198226, 0, 0), + c(-0.987301824, 0, -0.890961952, 0)) > > stopifnot(as.integer(estDAG$Adj) == trueDAG, + all.equal(estDAG$B, B.est, tol=1e-9)) > > if(doExtras) { + ## using pcalg + n <- nrow(X) + V <- colnames(X) # labels aka node names + + ## estimate CPDAG + pc.fit <- pc(suffStat = list(C = cor(X), n = n), + indepTest = gaussCItest, ## indep.test: partial correlations + alpha=0.01, labels = V, verbose = FALSE) + if (require(Rgraphviz)) { + plot(pc.fit, main = "Estimated CPDAG") + } + } > > ## if(!doExtras && !interactive()) quit("no") > > ### More tests for higher dimensions > > ### p = 8 -------- Example 3 ----------- > > set.seed(127) > n <- 2000 > x1 <- eps1 <- sign(rnorm(n)) * sqrt(abs(rnorm(n))) > x2 <- eps2 <- runif(n) - 0.5 > x3 <- eps3 <- sign(rnorm(n)) * abs(rnorm(n))^(1/3) > x4 <- eps4 <- rnorm(n)^2 > Z <- rnorm(n); eps5 <- sign(Z) * sqrt(abs(Z)) > Z <- rnorm(n); eps6 <- sign(Z) * sqrt(abs(Z)) > Z <- rnorm(n); eps7 <- sign(Z) * sqrt(abs(Z)) > Z <- rnorm(n); eps8 <- sign(Z) * sqrt(abs(Z)) > > x5 <- 7/8*x1 - 3/4*x2 + 3/4*x3 + eps5 > x6 <- 0.8*x4 + eps6 > x7 <- 3/4*x5 - 7/8*x6 + eps7 > x8 <- .9*x7 + eps8 > > X <- cbind(x1,x2,x3,x4,x5,x6,x7,x8, deparse.level = 2) > ## (x1, x2, x3) -> x5 -> x7 <- x6 <- x4; x7 -> x8 > ## adjacency matrix: > ## 1 2 3 4 5 6 7 8 > ## x1 . . . . 1 . . . > ## x2 . . . . 1 . . . > ## x3 . . . . 1 . . . > ## x4 . . . . . 1 . . > ## x5 . . . . . . 1 . > ## x6 . . . . . . 1 . > ## x7 . . . . . . . 1 > ## x8 . . . . . . . . > > ## true DAG : > . <- 0 > trDAG3 <- rbind( + c(., ., ., ., 1, ., ., .), + c(., ., ., ., 1, ., ., .), + c(., ., ., ., 1, ., ., .), + c(., ., ., ., ., 1, ., .), + c(., ., ., ., ., ., 1, .), + c(., ., ., ., ., ., 1, .), + c(., ., ., ., ., ., ., 1), + c(., ., ., ., ., ., ., .)) > > estB.3 <- rbind( + c(., ., ., ., ., ., ., .), + c(., ., ., ., ., ., ., .), + c(., ., ., ., ., ., ., .), + c(., ., ., ., ., ., ., .), + c(.831899433, -.737954104, 0.725137273, ., ., ., ., .), + c(., ., ., 0.788185348, ., ., ., .), + c(., ., ., ., 0.774490692, -0.886143314, ., .), + c(., ., ., ., ., ., 0.900617843, .)) > > eDAG3 <- LINGAM(X, verbose = 2) Centering Whitening Symmetric FastICA using logcosh approx. to neg-entropy function Iteration 1 tol = 0.7545483 Iteration 2 tol = 0.1655535 Iteration 3 tol = 0.04065082 Iteration 4 tol = 0.0001496655 Iteration 5 tol = 4.919493e-07 Iteration 6 tol = 3.187801e-09 Iteration 7 tol = 2.069445e-11 Iteration 8 tol = 2.204903e-13 Iteration 9 tol = 4.440892e-15 Performing row permutation, nzdiag*() ... (Small dimensionality, using brute-force method.): Done! Performing permutation for causal order... (Small dimensionality, using brute-force method.): Done! [,1] [,2] [,3] [,4] [,5] [1,] 0.00000000 0.002919480 -0.006553738 -0.003062375 0.0008261561 [2,] 0.02411382 0.000000000 -0.005439635 0.018401871 -0.0080918882 [3,] -0.08248625 0.007102494 0.000000000 -0.032518681 0.0119294275 [4,] -0.74202632 0.710888315 0.841560130 0.000000000 0.0104074191 [5,] -0.13439282 -0.029284805 -0.044231816 0.039214627 0.0000000000 [6,] -0.06915424 0.012373744 -0.013669545 0.002144062 0.7893267569 [7,] 0.04342903 -0.043525297 -0.005390509 0.751614899 0.0050000676 [8,] 0.01872415 -0.010379778 -0.003082474 0.024731302 0.0074836799 [,6] [,7] [,8] [1,] 0.003732972 0.0099985514 -0.005287321 [2,] -0.001156025 -0.0141942364 0.001135602 [3,] 0.012845090 0.0307525826 -0.018495408 [4,] -0.001767195 -0.0005324746 0.013116991 [5,] -0.032577376 -0.0289342038 0.020539625 [6,] 0.000000000 -0.0182766705 0.003333580 [7,] -0.864727090 0.0000000000 0.011545886 [8,] -0.018094416 0.8841932792 0.000000000 Causal B nicely triangular. No problems to report here. Pruning the network connections... Done! Warning message: In LINGAM(X, verbose = 2) : 'LINGAM' is deprecated. Use 'lingam' instead. See help("Deprecated") > > stopifnot(trDAG3 == eDAG3$Adj, + with(eDAG3, all(t(B != 0) == Adj)), + all.equal(eDAG3$B, estB.3, tol=1e-9)) > > > ### p = 10 -------- Example 4 ----------- > > ### using same x1..,x4, and, eps5 .. eps8 as in Ex. 3 > > Z <- rnorm(n); eps9 <- sign(Z) * abs(Z)^(1/3) > Z <- rnorm(n); eps10 <- sign(Z) * abs(Z)^0.25 > > x5 <- 7/8*x1 - 3/4*x2 + eps5 > x6 <- 0.8*x2 - 7/8*x3 + eps6 > x7 <- -7/8*x4 + eps7 > x8 <- 0.9*x2 - 0.8*x5 + eps8 > x9 <- -3/4*x6 + 7/8*x7 + eps9 > x10 <- 3/4*x6 + 0.5*x8 +0.9*x9 + eps10 > > X <- cbind(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10, deparse.level = 2) > > > ## true DAG : > . <- 0 > trDAG4 <- rbind( + # 1 2 3 4 5 6 7 8 9 0 + c(., ., ., ., 1, ., ., ., ., .), # 1 + c(., ., ., ., 1, 1, ., 1, ., .), # 2 + c(., ., ., ., ., 1, ., ., ., .), # 3 + c(., ., ., ., ., ., 1, ., ., .), # 4 + c(., ., ., ., ., ., ., 1, ., .), # 5 + c(., ., ., ., ., ., ., ., 1, 1), # 6 + c(., ., ., ., ., ., ., ., 1, .), # 7 + c(., ., ., ., ., ., ., ., ., 1), # 8 + c(., ., ., ., ., ., ., ., ., 1), # 9 + c(., ., ., ., ., ., ., ., ., .)) # 10 > > estB.4 <- rbind( + c(., ., ., ., ., ., ., ., ., .), + c(., ., ., ., ., ., ., ., ., .), + c(., ., ., ., ., ., ., ., ., .), + c(., ., ., ., ., ., ., ., ., .), + c(0.831899433, -0.737954104, ., ., ., ., ., ., ., .), + c(., 0.687919607, -0.863361084, ., ., ., ., ., ., .), + c(., ., ., -0.878305407, ., ., ., ., ., .), + c(., 0.864092647, ., ., -0.77902333, ., ., ., ., .), + c(., ., ., ., ., -0.780116888, 0.929828083, ., ., .), + c(., ., ., ., ., 0.72436897, ., 0.502210828, 0.913644804, .)) > > > eDAG4 <- LINGAM(X, verbose = TRUE) Performing row permutation, nzdiag*() ... (Using the Hungarian algorithm.): Done! Performing permutation for causal order... (Using pruning algorithm.): Done! [,1] [,2] [,3] [,4] [,5] [1,] 0.00000000 -0.006326785 0.0029431058 -0.003816060 0.004737111 [2,] -0.06430368 0.000000000 -0.0088146934 -0.035995357 0.025808763 [3,] 0.01297078 -0.006196360 0.0000000000 0.009575279 -0.012113841 [4,] -0.75694409 0.856720301 -0.0445599745 0.000000000 0.010837351 [5,] -0.12624203 -0.044575737 -0.0254719709 0.047144333 0.000000000 [6,] 0.72762061 -0.014204699 -0.8705396282 -0.006159921 -0.013464525 [7,] 0.02750857 -0.005321567 -0.0327098113 0.019033795 -0.842958526 [8,] 0.92330050 -0.003411800 -0.0048993505 -0.787883898 -0.010066586 [9,] -0.03478589 0.004801767 -0.0113849437 -0.011812608 0.018412819 [10,] 0.09828179 -0.004313719 -0.0005325424 0.016366714 0.020698254 [,6] [,7] [,8] [,9] [,10] [1,] -0.006504593 0.005701682 -0.009052809 -0.0072221244 0.0076433826 [2,] -0.009602760 0.031763460 -0.015247794 -0.0133862290 -0.0062761806 [3,] -0.008791438 -0.002404077 -0.005191894 -0.0244044833 0.0126367391 [4,] -0.026971906 0.019035635 0.007377126 -0.0190585825 0.0116252362 [5,] -0.019736049 0.003906628 0.029344715 0.0032010324 -0.0192788022 [6,] 0.000000000 -0.006334439 0.010147745 0.0009835252 -0.0126648632 [7,] 0.018792555 0.000000000 0.005190981 0.0225601097 0.0134526632 [8,] -0.003477516 -0.015750480 0.000000000 0.0015438015 -0.0024023179 [9,] -0.766570434 0.896089525 -0.002912303 0.0000000000 0.0007192613 [10,] 0.735553224 -0.001853620 0.501052022 0.9124372652 0.0000000000 Causal B nicely triangular. No problems to report here. Pruning the network connections... Done! Warning message: In LINGAM(X, verbose = TRUE) : 'LINGAM' is deprecated. Use 'lingam' instead. See help("Deprecated") > > stopifnot(trDAG4 == eDAG4$Adj, + with(eDAG4, all(t(B != 0) == Adj)), + all.equal(eDAG4$B, estB.4, tol=1e-9)) > > proc.time() user system elapsed 1.43 0.23 1.67