I am trying to reproduce a network i have previously created in GeNie, but i get an error that some conditional probability distributions of node probability do not sum to one.
# create empty BN
HazardNet <- empty.graph(nodes = c("scenario", "probability", "intensity", "hazard"))
HazardNet
# dependencies
HazardNet <- set.arc(HazardNet, from = "scenario", to = "probability")
HazardNet <- set.arc(HazardNet, from = "scenario", to = "intensity")
HazardNet <- set.arc(HazardNet, from = "intensity", to = "hazard")
HazardNet <- set.arc(HazardNet, from = "probability", to = "hazard")
HazardNet
# define states - global distribution
lmh <- c("low", "moderate", "high")
scenario.lv <- c("30 year", "100 year", "300year", "none")
intensity.lv <- lmh
probability.lv <- lmh
hazard.lv <- lmh
# create conditional probability tables
scenario.prob <- array(c(0.01, 0.03, 0.05, 0.91), dim = 4,
dimnames = list(scenario = scenario.lv))
probability.prob <- array(c(rep(1/3, 12)), dim = c(4,3),
dimnames = list(scenario =scenario.lv, probability = probability.lv))
intensity.prob <- array(c(0, 0.5, 0.5, 0, 0.3, 0.7, 0, 0.1, 0.9, 0.98, 0.019, 0.001), dim = c(3, 4),
dimnames = list(intensity = intensity.lv, scenario = scenario.lv ))
hazard.prob <- array(c(0, 1, 0, 0.5, 0.5, 0, 1, 0, 0, 0.5, 0.5, 0, 0, 1, 0, 0, 0.5, 0.5, 0, 0, 1, 0, 0, 1, 0, 0, 1 ),
dim = c(3, 3, 4),
dimnames = list( intensity = intensity.lv, hazard= hazard.lv, scenario = scenario.lv))
cpt <- list(scenario = scenario.prob, probability = probability.prob, intensity = intensity.prob, hazard = hazard.lv)
bn <- custom.fit(HazardNet, cpt)
I assume the problem is the node scenario? If I see right all my other cpt are fine.
How can i code equal probabilities for a node with 3 states?
> scenario.prob
scenario
30 year 100 year 300year none
0.01 0.03 0.05 0.91
> probability.prob
probability
scenario low moderate high
30 year 0.3333333 0.3333333 0.3333333
100 year 0.3333333 0.3333333 0.3333333
300year 0.3333333 0.3333333 0.3333333
none 0.3333333 0.3333333 0.3333333
> intensity.prob
scenario
intensity 30 year 100 year 300year none
low 0.0 0.0 0.0 0.980
moderate 0.5 0.3 0.1 0.019
high 0.5 0.7 0.9 0.001
> hazard.prob
, , scenario = 30 year
hazard
intensity low moderate high
low 0 0.5 1
moderate 1 0.5 0
high 0 0.0 0
, , scenario = 100 year
hazard
intensity low moderate high
low 0.5 0 0.0
moderate 0.5 1 0.5
high 0.0 0 0.5
, , scenario = 300year
hazard
intensity low moderate high
low 0 0 0
moderate 0 0 0
high 1 1 1
, , scenario = none
hazard
intensity low moderate high
low 0 0.5 1
moderate 1 0.5 0
high 0 0.0 0