Description Usage Arguments Author(s) Examples
View source: R/make_bnlearn_evidence.R
Take a fully specified bayesian network, a list nodes states names after the node names or character vector of node names, and return a list of query formated following the bnlearn package specifications.
1 | make_bnlearn_evidence(bn, evidence)
|
bn |
an object of class |
evidence |
list or character vector specify the states or nodes based on which the evidences are to be formated. |
Issoufou Liman
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | library (gRain)
library(bnlearn)
## setting a bayesian network with gRain
Soil_type <- cptable (~Soil_type, values = c(0.05, 0.55, 0.4),
levels = c('Sandy', 'Loamy', 'Clayey'))
Manure_application <- cptable(~Manure_application, values = c(0.3, 0.7),
levels = c('FALSE', 'TRUE'))
Soil_water_holding_capacity_tmp <- make_gRain_CPT(
parent_effects = list(c(0, 2.5, 3), c(0, 2)),
parent_weights = c(2,1),
b = 3,
child_prior = c(0.2,0.5,0.3),
child_states = c('Low', 'Medium', 'High'),
parent_states = list(c('Sandy', 'Loamy', 'Clayey'), c('FALSE', 'TRUE'))
)
Soil_water_holding_capacity_values <- Soil_water_holding_capacity_tmp$values
Soil_water_holding_capacity_levels <- Soil_water_holding_capacity_tmp$levels
Soil_water_holding_capacity <- cptable (
~Soil_water_holding_capacity|Soil_type:Manure_application,
values = Soil_water_holding_capacity_values,
levels = Soil_water_holding_capacity_levels)
## Compile conditional probability tables
network <- compileCPT(list(Soil_type, Manure_application, Soil_water_holding_capacity))
## Graphical Independence Network ####
network <- grain(network)
## Use grain object (gRain package)
make_bnlearn_evidence (bn = network, evidence = c('Soil_type', 'Manure_application'))
make_bnlearn_evidence (bn = network,
evidence = list(Soil_type = c('Sandy', 'Loamy', 'Clayey'), Manure_application = c('FALSE', 'TRUE')))
make_bnlearn_evidence (bn = network,
evidence = list(Soil_type = 'Sandy', Manure_application = c('FALSE', 'TRUE')))
## converting the grain bayesian network to bn.fit
network_bn_fit <- as.bn.fit(network)
## Use bn.fit object (bnlearn package)
make_bnlearn_evidence (bn = network_bn_fit, evidence = c('Soil_type', 'Manure_application'))
make_bnlearn_evidence (bn = network_bn_fit,
evidence = list(Soil_type = c('Sandy', 'Loamy', 'Clayey'), Manure_application = c('FALSE', 'TRUE')))
make_bnlearn_evidence (bn = network_bn_fit,
evidence = list(Soil_type = 'Sandy', Manure_application = c('FALSE', 'TRUE')))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.