70 Bayesian Networks: With Examples in R
> dimnames(dsd) <- list(D = c("thin", "average", "thick"),
+ S = c("s1", "s2"))
> dsd
S
D s1 s2
thin 0.88493 0.03593
average 0.07914 0.07914
thick 0.03593 0.88493
Subsequently, we compute the joint distribution of D and S by multiplying dsd
by the probability of each S, which we stored in sp when we loaded the JAGS
model.
> jointd <- dsd * sp
Finally, we compute the conditional probability of S given D by dividing each
row by its total, which we compute using rowSums, and by transposing the
resulting matrix with the t function.
> dds <- t(jointd / rowSums(jointd))
> dds
D
S thin average thick
s1 0.96098 0.5 0.03902
s2 0.03902 0.5 0.96098
Using rjags, we can assess the probability of each supplier using either
the contin