[R] Get the graph of CAM (Causal additive model)?

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sat Mar 18 22:58:46 CET 2023


Dear R-experts,

Here below my R code working but I would like to plot (get the graph) of the Causal additive model exactly the same way I get the graph (CPDAG) from the bnlearn R package. Is it possible? If yes, how?
Many thanks

###################################
# libraries
library(devtools)
install_url('http://cran.r-project.org/src/contrib/Archive/CAM/CAM_1.0.tar.gz')
library(CAM)
library("bnlearn")
library(Rgraphviz)
 
# data
x1=c(-0.6,28.3,-1.6,-2.8,18.8,7.0,25.8,-2.8,7.2,-2.0,-5.1,0.6,-10.2,-21.0,-19.1,19.0, -19.2,-2.7, -2.5, -16.4, -13.5, 13.7, 10.1, -25.3, 8.5, -5.6, 3.1, -9.2, -3.7, -6.6, 13.9, 18.2, 6.5, 2.3)
 
x2=c(4.1, 9.3, -0.7, 6.7, -5.9, 0.2, 10.3, -9.6, -0.4, -16.2, 3.8, 0.2, 23.5, 0.0, 8.7, 2.0, 9.4, 0.0, -16.5, 5.3, 2.3, 7.5, 4.6, -1.9, -5.4, 10.7, 2.3, 4.6, -2.5, -4.7, 0.0, -1.9, 4.7, -14.4)
 
x3=c(3.9, 1.8, -1.0, -1.4, -3.7, -3.0, 6.0, -6.2, 5.5, 2.3, 6.9, -1.2, -4.7, 8.9, -6.0, 13.7, 2.0, -4.1, -3.9, -3.6, -5.6, 0.2, -7.1, -4.6, -0.6, -12.4, -7.7, -1.6, 10.6, -2.8, 12.3, -5.4, 9.7, 11.3)
 
x4=c(-0.4, -1.7, -4.7, 1.1, 4.3, -15.7, -0.5, -4.9, 12.9, -3.5, 8.6, 2.8, -5.2, 11.7, 22.9, 7.7, 5.9, -12.2, -18.9, -7.4, 1.6, -1.2, -1.7, 1.6, 1.2, -12.6, -9.0, -0.2, 11.3, -10.3, 6.3, -2.7, 0.4, 3.6)
 
x5=c(-4.3, 5.1, 10.5, -0.4, 5.1, 10.0, 1.2, 0.5, 10.9, -1.3, -5.5, 4.3, 10.0, 5.0, -4.0, -1.8, -4.3, 1.9, -9.9, 2.5, 17.5, -4.3, 10.6, 8.8, -2.8, 3.5, 6.9, -1.4, -4.7, -3.2, 2.2, 0.4, 3.7, 7.2)
 
A= data.frame(x1,x2,x3,x4,x5)
 
# CPDAG using bnlearn R package
boot = boot.strength(A, R=10000, algorithm = "hc")
head(boot[(boot$strength > 0.70) & (boot$direction >= 0.5), ], n = 10)
boot
res = hc(A)
a=cpdag(res)
plot(a)
 
# Causal additive model
X <- cbind(x1,x2,x3,x4,x5)
estDAG <- CAM(X, scoreName = "SEMGAM", numCores = 1, output = TRUE, variableSel = FALSE, pruning = TRUE, pruneMethod = selGam, pruneMethodPars = list(cutOffPVal = 0.001))
###################################
 



More information about the R-help mailing list