Learn R Programming

easybgm (version 0.3.1)

easybgm_compare: Compare networks across groups using Bayesian inference

Description

Easy comparison of networks using Bayesian inference to extract differences in conditional (in)dependence across groups.

Usage

easybgm_compare(
  data,
  type,
  package = NULL,
  not_cont = NULL,
  group_indicator = NULL,
  iter = 10000,
  save = TRUE,
  progress = TRUE,
  ...
)

Value

The returned object of easybgm contains several elements:

  • parameters A p x p matrix containing difference across partial associations.

  • inc_probs A p x p matrix containing the posterior inclusion probabilities of subgroup differences.

  • inc_BF A p x p matrix containing the posterior inclusion Bayes factors of subgroup differences.

  • structure Adjacency matrix of the median probability model (i.e., edges with a posterior probability larger 0.5).

In addition, for 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_graph A vector containing the indexes of a particular structure.

  • convergence_parameter A vector containing the R-hat (Gelman–Rubin) statistic for the difference parameter measuring how well MCMC chains have converged to the same target distribution.

For both packages, when setting save = TRUE, the function will also return the following object:

  • samples_posterior A k x iter matrix containing the posterior samples of parameter differences (i.e., k = (p/(p-1))/2) at each iteration (i.e., iter) of the sampler.

Arguments

data

A list with two n x p matrices or dataframes containing the variables for n independent observations on p variables for two groups. Note that the variables need to be the same in the two different dataframes. Alternatively, when "bgms" version > 0.1.6 is installed, 'data' can also be a matrix of binary and ordinal responses from all groups. If this is the case, the 'group_indicator' argument also needs to be specified.

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 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).

group_indicator

Optional integer vector of group memberships for the rows of the dataframe (multi-group comparison), when data is a matrix instead of a list of two dataframes.

iter

number of iterations for the sampler. Default is 1e4.

save

Logical. Should the posterior samples be obtained (default = TRUE)?

progress

Logical. Should a progress bar be shown (default = TRUE)?

...

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. Please consult the original packages "bgms" and "BGGM" for the specific informed prior options.

We always encourage researcher to conduct prior robustness checks.

Examples

Run this code

# \donttest{
library(easybgm)
library(bgms)

data <- na.omit(ADHD)

group1 <- data[1:10, 1:3]
group2 <- data[11:20, 1:3]

# Fitting the Wenchuan PTSD data

fit <- easybgm_compare(list(group1, group2), 
                type = "binary", save = TRUE,
                iter = 50 # for demonstration only (> 5e4 recommended)
                )

summary(fit)

# For multigroup estimation
fit_multi <- easybgm_compare(data[1:200, 1:5], 
                group_indicator = rep(c(1, 2, 3, 4), each = 50),
                type = "binary", save = TRUE, 
                iter = 100 # for demonstration only (> 5e4 recommended)
                )

summary(fit_multi)
# }

Run the code above in your browser using DataLab