R颗粒错误-表尺寸不匹配

R颗粒错误-表尺寸不匹配,r,bayesian,R,Bayesian,我正在使用R中的gRain包创建一个贝叶斯网络。当试图编译条件概率表时,我得到错误“表维度不匹配”。所讨论的表格采用A | B的形式,其中A可以取三个可能的值,B可以取两个。基于六种可能的组合,我在cptable定义中总共输入了12个值。任何帮助都将不胜感激,因为我检查和研究都没有结果,也看不出哪里出了问题。这是我的密码 # define levels lh <- c("low", "high") lmh <- c("low", "medium", "high") # specif

我正在使用R中的gRain包创建一个贝叶斯网络。当试图编译条件概率表时,我得到错误“表维度不匹配”。所讨论的表格采用A | B的形式,其中A可以取三个可能的值,B可以取两个。基于六种可能的组合,我在cptable定义中总共输入了12个值。任何帮助都将不胜感激,因为我检查和研究都没有结果,也看不出哪里出了问题。这是我的密码

# define levels
lh <- c("low", "high")
lmh <- c("low", "medium", "high")

# specify the conditional probability tables
eh <- cptable(~eh, values=c(0.2, 0.8), levels=lh)
inf.oil.eh <- cptable(~inf | oil:eh, values = c(0.9, 0.1, 0.1, 0.9, 0.1, 0.9, 0.01, 0.99), levels=lh)
bp.oil <- cptable(~bp | oil, values=c(0.9, 0.1, 0.1, 0.9, 0, 1, 0.1, 0.9, 0.4, 0.6, 0.5, 0.5), levels=lmh)
oil.eh <- cptable(~oil | eh, values=c(0.9, 0.1, 0.05, 0.95), levels=lh)
rt.inf.eh <-cptable(~rt | inf:eh, values=c(0.9, 0.1, 0.1, 0.9, 0.1, 0.9, 0.01, 0.99), levels=lh)
# compile the tables
plist <- compileCPT(list(eh, oil.eh, inf.oil.eh, bp.oil, rt.inf.eh))

bp | oil
的条件概率表指定的值太多。由于
oil
有两个级别和
bp
3,您需要6个条件概率,但行中有12个

bp.oil <- cptable(~bp | oil, values=c(0.9, 0.1, 0.1, 0.9, 0, 1, 0.1, 0.9, 0.4, 0.6, 0.5, 0.5), levels=lmh)

bp.oil感谢Harald-我已经习惯于将两个值变量的p,1-p成对相加,并且在这里做了同样的事情@凯特,你是怎么解决这个问题的?我得到了确切的错误和同样的问题
bp.oil <- cptable(~bp | oil, values=c(0.9, 0.1, 0.1, 0.9, 0, 1, 0.1, 0.9, 0.4, 0.6, 0.5, 0.5), levels=lmh)