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 |
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_alpha
the parameters of the "Beta-Bernoulli" or "Stochastic Block" priors. The default is 1 for both.
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"
.
reference_category
he reference category in the Blume-Capel model.
Should be an integer within the range of integer scores observed for the
'blume-capel' variable. Can be a single number specifying the reference
category for all Blume-Capel variables at once, or a vector of length
p
where the i
-th element contains the reference category for
variable i
if it is Blume-Capel, and bgm ignores its elements for
other variable types. The value of the reference category is also recoded
when bgm recodes the corresponding observations. Only required if there is at
least one variable of type “blume-capel”.
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.
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.