| easybgm | R Documentation |
Easy estimation of a Bayesian analysis of networks to obtain conditional (in)dependence relations between variables in a network.
easybgm(
data,
type,
package = NULL,
not_cont = NULL,
iter = 10000,
save = FALSE,
centrality = FALSE,
progress = TRUE,
posterior_method = "model-averaged",
...
)
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, or blume-capel. |
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. |
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_scale the scale of the Cauchy distribution that is used as a
prior for the pairwise interaction parameters. The default is 2.5.
edge_prior prior on the graph structure, which can be either "Bernoulli", "Beta-Bernoulli" or "Stochastic Block". The default is "Bernoulli".
inclusion_probability prior edge inclusion probability for the "Bernoulli" distribution. The default is 0.5.
beta_bernoulli_alpha and beta_bernoulli_beta the parameters of the "Beta-Bernoulli" or "Stochastic Block" priors. The default is 1 for both.
beta_bernoulli_alpha_between and beta_bernoulli_beta_between the parameters of the "Stochastic Block" prior for edges between blocks.
This is currently only available in a developer version of bgms and will be available in version 0.1.6.2 or higher.
dirichlet_alpha The shape of the Dirichlet prior on the node-to-block
allocation parameters for the Stochastic Block prior on the graph structure.
threshold_alpha and threshold_beta the parameters of the beta-prime distribution for the threshold parameters. The defaults are both set to 1.
variable_type What kind of variables are there in x? Can be a
single character string specifying the variable type of all p
variables at once or a vector of character strings of length p
specifying the type for each variable in x separately. Currently, bgm
supports ordinal'' and blume-capel”. Binary variables are automatically
treated as “ordinal’’. Defaults to variable_type = "ordinal".
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 3.
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.
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 the bgms package, when edge_prior = "Stochastic-Block",
the function will also return an object sbm which contains:
posterior_num_blocks A data frame with the estimated posterior
probability of the possible number of clusters.
posterior_mean_allocations The posterior mean of the cluster assignments of the nodes.
posterior_mode_allocations The posterior mode of the cluster assignments of the nodes.
posterior_mean_coclustering_matrix A p x p matrix containing the estimated
pairwise proportions of cluster occurrence of every variable. This matrix
can be plotted to visually inspect the estimated number of clusters
and visually inspect nodes that tend to switch clusters.
If using version 0.1.6.1 or higher of the bgms package, the function also returns the
the Gelman-Rubin convergence statistic for each edge weight parameter. As well as the
95% Monte Carlo confidence interval for the inclusion Bayes factor.
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.
library(easybgm)
library(bgms)
data <- na.omit(Wenchuan)
# Fitting the Wenchuan PTSD data
fit <- easybgm(data, type = "continuous",
iter = 100 # for demonstration only (> 5e4 recommended)
)
summary(fit)
# To extract the posterior parameter distribution
# and centrality measures
fit <- easybgm(data, type = "continuous",
iter = 100,
centrality = TRUE, save = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.