Description Usage Arguments Details Author(s) References See Also Examples
View source: R/make_node_states_estimates.R
create a multivariate estimate
object for Bayesian network node.
The function samples from the posterior distribution of the Bayesian network to construct an
object of class estimate
accounting for each state of the node.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | make_node_states_estimates(
bn,
node,
op = "proba",
distr = "beta",
n_run = 1000,
state_effects = NULL,
evidence = NULL,
n_generation = NULL,
include_relatives = TRUE,
estimate_method = "fit",
percentiles = c(0.025, 0.5, 0.975),
plot = FALSE,
show.output = FALSE,
fit = c("emp", "theo"),
emp_estimates = NULL
)
|
bn |
an object of class bn.fit. |
node |
character string, the label of the node which conditional distribution is of interest. |
op |
a vector of character strings, the type of returned value: either probabilities or raw data sampled from the posterior distribution |
distr |
charater vector. The expected probability distribution function. |
n_run |
integer specifying the number of of model run. Default is 1000. |
state_effects |
numeric vector specifying the relative weight factor of each state in the final estimate. |
evidence |
a name value pair:a named character vector which values are node states and names are node names. |
n_generation |
how far to go in the network topology for building the conditionning specification for the query? |
include_relatives |
logical Should parents or ancestors, depending on the the argument n_generation, should be included in the query? If TRUE, the default, these will be internally involved in constructing the evidence argument. |
estimate_method |
character vector. Method to be used for estimating the marginal distribution parameters as in |
percentiles |
numeric vector of percentiles based on which to define a quantile function to be used for fitting distr with rriskDistributions package. |
plot |
logical. Should the quantile function be ploted? default to FALSE |
show.output |
Should the computation be verbose? default to FALSE |
fit |
character specifying whether the estimates should be derived from either empirical ('emp', default) or theoritical distribution ('theo'). |
emp_estimates |
list alternative estimates specification.Default to NULL. This is only used when fit = 'theo'. |
see estimate
.
Issoufou Liman
Eike Luedeling and Lutz Goehring (2018). decisionSupport: Quantitative Support of Decision Making under Uncertainty. R package version 1.103.8. https://CRAN.R-project.org/package=decisionSupport
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 | 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_node_states_estimates (bn = network, node = 'Soil_water_holding_capacity')
## converting the grain bayesian network to bn.fit
network_bn_fit <- as.bn.fit(network)
## Use bn.fit object (bnlearn package)
make_node_states_estimates (bn = network_bn_fit,
node = 'Soil_water_holding_capacity', distr = c('beta', 'norm', 'gamma'))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.