1
RのgRainパッケージを使用してベイジアンネットワークを作成しています。条件付き確率表をコンパイルしようとすると、「表の次元が一致しません」というエラーが発生します。問題の表は、A | Bの形式を取ります。ここで、Aは3つの値を取り、Bは2つの値をとることができます。私は6つの可能な組み合わせに基づいて、cptable定義に合計12の値を入力しました。どのような助けが私がチェックし、無駄に調査し、何がうまくいかないのを見ることができないので、非常に高く評価されるだろう。これは私のコードです。次のようにRエラー - 表のサイズが一致しない
# 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))
エラーは次のとおりです。
Error for v,pa(v): bp, oil
List of 2
$ bp : chr [1:3] "low" "medium" "high"
$ oil: chr [1:2] "low" "high"
num [1:12] 0.9 0.1 0.1 0.9 0 1 0.1 0.9 0.4 0.6 ...
Error in compileCPT(list(eh, oil.eh, inf.oil.eh, bp.oil, rt.inf.eh)) :
Table dimensions do not match!
おかげハラルドに12を持っていますそして同じことをここでやった! – Kate