fit_node_states_distr: Fitting univariate distributions to Bayesain network nodes

Description Usage Arguments Details Author(s) References See Also Examples

View source: R/fit_node_states_distr.R

Description

Fitting univariate distributions to the posterior distribution of a Bayesian network node.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
fit_node_states_distr(
  bn,
  node,
  op = "proba",
  distr = "beta",
  method = "mme",
  start = NULL,
  fix.arg = NULL,
  discrete,
  keepdata = TRUE,
  keepdata.nb = 100,
  include_relatives = TRUE,
  n_run = 1000,
  ...
)

Arguments

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

A character string "name" naming a distribution for which the corresponding density function dname, the corresponding distribution function pname and the corresponding quantile function qname must be defined, or directly the density function.

method

A character string coding for the fitting method: "mle" for 'maximum likelihood estimation', "mme" for 'moment matching estimation', "qme" for 'quantile matching estimation', "mge" for 'maximum goodness-of-fit estimation' and "mse" for 'maximum spacing estimation'.

start

A named list giving the initial values of parameters of the named distribution or a function of data computing initial values and returning a named list. This argument may be omitted (default) for some distributions for which reasonable starting values are computed (see the 'details' section of mledist). It may not be into account for closed-form formulas.

fix.arg

An optional named list giving the values of fixed parameters of the named distribution or a function of data computing (fixed) parameter values and returning a named list. Parameters with fixed value are thus NOT estimated by this maximum likelihood procedure. The use of this argument is not possible if method="mme" and a closed-form formula is used.

discrete

If TRUE, the distribution is considered as discrete. If discrete is missing, discrete is automaticaly set to TRUE when distr belongs to "binom", "nbinom", "geom", "hyper" or "pois" and to FALSE in the other cases. It is thus recommended to enter this argument when using another discrete distribution. This argument will not directly affect the results of the fit but will be passed to functions gofstat, plotdist and cdfcomp.

keepdata

a logical. If TRUE, dataset is returned, otherwise only a sample subset is returned.

keepdata.nb

When keepdata=FALSE, the length (>1) of the subset returned.

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.

n_run

integer specifying the number of of model run. Default is 1000.

...

Further arguments to be passed to generic functions, or to one of the functions "mledist", "mmedist", "qmedist" or "mgedist" depending of the chosen method. See mledist, mmedist, qmedist, mgedist for details on parameter estimation.

Details

see fitdist.

Author(s)

Issoufou Liman

References

Marie Laure Delignette-Muller, Christophe Dutang (2015). fitdistrplus: An R Package for Fitting Distributions. Journal of Statistical Software, 64(4), 1-34. http://www.jstatsoft.org/v64/i04/.

See Also

fitdist.

Examples

 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
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)
fit_node_states_distr (bn = network, node = 'Soil_water_holding_capacity', gof='KS')
## converting the grain bayesian network to bn.fit
network_bn_fit <- as.bn.fit(network)
## Use bn.fit object (bnlearn package)
fit_node_states_distr (bn = network_bn_fit,
node = 'Soil_water_holding_capacity', distr = c('beta', 'norm', 'gamma'))

Issoufou-Liman/decisionSupportExtra documentation built on Dec. 21, 2020, 6:28 p.m.