#### Problem with the `pdag2allDags` and `addBgKnowledge` functions on pcalg package

``````library(pcalg)
library(Rgraphviz)
data("gmG")
df<-gmG\$x
suffStat <- list(C = cor(df), n = nrow(df))
fci.fit<-fci(suffStat, indepTest = gaussCItest, p = ncol(df),alpha = 0.01)
plot(fci.fit)
``````

``````plotAllDags <- function(res) {
require(graph)
p <- sqrt(ncol(res\$dags))
nDags <- ceiling(sqrt(nrow(res\$dags)))
par(mfrow = c(nDags, nDags))
for (i in 1:nrow(res\$dags)) {
tmp <- matrix(res\$dags[i,],p,p)
colnames(tmp) <- rownames(tmp) <- res\$nodeNms
plot(as(tmp, "graphNEL"))
}
}

res1<-pdag2allDags(as(fci.fit,"amat"))
plotAllDags(res1)
``````

sqrt(ncol(res\$dags)) 中的错误：数学函数的非数字参数

``````res2<-pdag2allDags(fci.fit@amat)
plotAllDags(res2)
``````

sqrt(ncol(res\$dags)) 中的错误：数学函数的非数字参数

``````pc.fit<-pc(suffStat, indepTest = gaussCItest, p = ncol(df),alpha = 0.01)
plot(pc.fit)
res0<-pdag2allDags(as(pc.fit,"amat"))
plotAllDags(res0)
``````

``````pc.amat2<-addBgKnowledge(gInput = pc.fit@graph,x=1,y=2)
plot(pc.amat2)
``````

``````fci.amat2<-addBgKnowledge(gInput = as(fci.fit,"amat"),x=1,y=2)
plot(as(t(fci.amat2),"graphNEL"))
``````

h(simpleError(msg, call)) 中的错误：在为函数“plot”选择方法时评估参数“x”时出错：参数不是矩阵

1 个回复

``````as(pc.fit,"amat")
``````

``````Adjacency Matrix 'amat' (8 x 8) of type ‘cpdag’:
1 2 3 4 5 6 7 8
1 . 1 . . . . . .
2 1 . 1 . 1 . . .
3 . 1 . . . . . .
4 . . . . . . . .
5 . 1 . . . . . .
6 1 . . . 1 . . .
7 . . . . . 1 . .
8 1 . . . 1 . . .
``````

``````as(fci.fit,"amat")
``````

``````Adjacency Matrix 'amat' (8 x 8) of type ‘pag’:
1 2 3 4 5 6 7 8
1 . 1 . . . 2 . 2
2 1 . 1 . 1 . . .
3 . 1 . . . . . .
4 . . . . . . . .
5 . 1 . . . 2 . 2
6 3 . . . 3 . 2 .
7 . . . . . 3 . .
8 3 . . . 3 . . .
``````

``````fci.fit@amat
``````

``````  1 2 3 4 5 6 7 8
1 0 1 0 0 0 2 0 2
2 1 0 1 0 1 0 0 0
3 0 1 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0
5 0 1 0 0 0 2 0 2
6 3 0 0 0 3 0 2 0
7 0 0 0 0 0 3 0 0
8 3 0 0 0 3 0 0 0
``````

`pcalg`对文档`pdag2allDags`没有明确提到...

• 函数定义说'一个给定的部分有向无环图（PDAG）'。
• 该示例显示了一个定义为 0 和 1 的矩阵的“ `amat` ”，与`fci``pc`函数没有任何联系

• 3 表示列是原因，行是结果......
• 和 2 表示列是结果，行是原因......

``````pag2cpdag<-function(fciAlgo){
res<-as(fciAlgo,"amat")#a amat type pag
res[res==3]<-1
res[res==2]<-0
return(res)
}
``````

``````pag2cpdag(fci.fit)
``````

``````Adjacency Matrix 'amat' (8 x 8) of type ‘pag’:
1 2 3 4 5 6 7 8
1 . 1 . . . . . .
2 1 . 1 . 1 . . .
3 . 1 . . . . . .
4 . . . . . . . .
5 . 1 . . . . . .
6 1 . . . 1 . . .
7 . . . . . 1 . .
8 1 . . . 1 . . .
``````

``````res1<-pdag2allDags(pag2cpdag(fci.fit))
plotAllDags(res1)
``````

``````fci.amat2<-addBgKnowledge(gInput = pag2cpdag(fci.fit),x=1,y=2)
plot(as(t(fci.amat2),"graphNEL"))
``````

``````Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'plot': no method or default for coercing “amat” to “graphNEL”
``````

``````fci.amat2
``````

``````Adjacency Matrix 'amat' (8 x 8) of type ‘pag’:
1 2 3 4 5 6 7 8
1 . . . . . . . .
2 1 . . . . . . .
3 . 1 . . . . . .
4 . . . . . . . .
5 . 1 . . . . . .
6 1 . . . 1 . . .
7 . . . . . 1 . .
8 1 . . . 1 . . .
``````

``````pc.amat2<-addBgKnowledge(pag2cpdag(fci.fit),x=1,y=2)
class(pc.amat2)<-"matrix"
plot(as(t(pc.amat2),"graphNEL"))
``````
1 基类的模板参数包上的C ++ 11调用成员函数（如果存在）

2014-10-01 13:20:15 1 710   c++/ c++11
2 pcalg的PC稳定

3 面对问题以在烤面包上显示消息

2011-07-10 18:46:37 3 242   android
4 使用laravel Image包上传.JPG文件的问题

2021-06-27 06:35:30 0 16   php/ image
5 NodeJS在Azure软件包上的部署问题

2017-08-18 05:55:13 1 294   azure
6 Modelica的样本函数存在问题

7 我的函数存在问题：discord js的updateChannel

2019-11-27 14:19:16 2 43   discord
8 在函数中存在mmap问题

10 cMath和sin函数存在问题