easybgm {easybgm} | R Documentation |
Fit a Bayesian analysis of networks
Description
Easy estimation of a Bayesian analysis of networks to obtain conditional (in)dependence relations between variables in a network.
Usage
easybgm(
data,
type,
package = NULL,
not_cont = NULL,
iter = 10000,
save = FALSE,
centrality = FALSE,
progress = TRUE,
posterior_method = "model-averaged",
...
)
Arguments
data |
An n x p matrix or dataframe containing the variables for n independent observations on p variables. |
type |
What is the data type? Options: continuous, mixed, ordinal, binary |
package |
The R-package that should be used for fitting the network model; supports BGGM, BDgraph, and bgms. Optional argument; default values are specified depending on the datatype. |
not_cont |
If data-type is mixed, a vector of length p, specifying the not-continuous variables (1 = not continuous, 0 = continuous). |
iter |
number of iterations for the sampler. |
save |
Logical. Should the posterior samples be obtained (default = FALSE)? |
centrality |
Logical. Should the centrality measures be extracted (default = FALSE)? Note, that it will significantly increase the computation time. |
progress |
Logical. Should a progress bar be shown (default = TRUE)? |
posterior_method |
Determines how the posterior samples of the edge weight parameters are obtained for models fit with BDgraph. The argument can be either MAP for the maximum-a-posteriori or model-averaged. If MAP, samples are obtained for the edge weights only for the most likely structure. If model-averaged, samples are obtained for all plausible structures weighted by their posterior probability. Default is model-averaged. |
... |
Additional arguments that are handed to the fitting functions of the packages, e.g., informed prior specifications. |
Details
Users may oftentimes wish to deviate from the default, usually uninformative, prior specifications of the
packages to informed priors. This can be done by simply adding additional arguments to the easybgm
function.
Depending on the package that is running the underlying network estimation, researcher can specify different prior
arguments. We give an overview of the prior arguments per package below.
bgms:
-
interaction_prior
prior distribution of the interaction parameters, can be either "UnitInfo" for the Unit Information prior, or "Cauchy" for the Cauchy distribution. The default is set to "UnitInfo". -
edge_prior
prior on the graph structure, which can be either "Bernoulli" or "Beta-Bernoulli". The default is "Bernoulli". -
inclusion_prior
prior edge inclusion probability for the "Bernoulli" distribution. The default is 0.5. -
beta_bernoulli_alpha
andbeta_bernoulli_alpha
the parameters of the "Beta-Bernoulli" distribution. The default is 1 for both. -
threshold_alpha
andthreshold_beta
the parameters of the beta-prime distribution for the threshold parameters. The defaults are both set to 1.
BDgraph:
-
df.prior
prior on the parameters (i.e., inverse covariance matrix), degrees of freedom of the prior G-Wishart distribution. The default is set to 2.5. -
g.prior
prior probability of edge inclusion. This can be either a scalar, if it is the same for all edges, or a matrix, if it should be different among the edges. The default is set to 0.5.
BGGM:
-
prior_sd
the standard deviation of the prior distribution of the interaction parameters, approximately the scale of a beta distribution. The default is 0.25.
We would always encourage researcher to conduct prior robustness checks.
Value
The returned object of easybgm
contains several elements:
-
parameters
A p x p matrix containing partial associations. -
inc_probs
A p x p matrix containing the posterior inclusion probabilities. -
BF
A p x p matrix containing the posterior inclusion Bayes factors. -
structure
Adjacency matrix of the median probability model (i.e., edges with a posterior probability larger 0.5).
In addition, for BDgraph
and bgms
, the function returns:
-
structure_probabilities
A vector containing the posterior probabilities of all visited structures, between 0 and 1. -
graph_weights
A vector containing the number of times a particular structure was visited. -
sample_graphs
A vector containing the indexes of a particular structure.
For all packages, when setting save = TRUE
and centrality = TRUE
, the function will return the following objects respectively:
-
samples_posterior
A k x iter matrix containing the posterior samples for each parameter (i.e., k = (p/(p-1))/2) at each iteration (i.e., iter) of the sampler. -
centrality
A p x iter matrix containing the centrality of a node at each iteration of the sampler.
Examples
library(easybgm)
library(bgms)
data <- na.omit(Wenchuan)
# Fitting the Wenchuan PTSD data
fit <- easybgm(data, type = "continuous",
iter = 1000 # for demonstration only (> 5e4 recommended)
)
summary(fit)
# To extract the posterior parameter distribution
# and centrality measures
fit <- easybgm(data, type = "continuous",
iter = 1000, # for demonstrative purposes, generally, 1e5 iterations are recommended
save = TRUE,
centrality = TRUE)