Skip to content

Commit 02cf8a7

Browse files
Update package documentation.
Easybgm shim.
1 parent 93181e8 commit 02cf8a7

File tree

4 files changed

+103
-89
lines changed

4 files changed

+103
-89
lines changed

R/bgm.R

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ bgm = function(
392392
}
393393
if(hasArg(save)) {
394394
warning("The argument save is deprecated. Everything is saved in the function output.")
395-
} else {
396-
save = TRUE
397395
}
398396
if(hasArg(threshold_alpha) || hasArg(threshold_beta)) {
399397
if(!hasArg(main_alpha))
@@ -607,14 +605,34 @@ bgm = function(
607605
hmc_num_leapfrogs = hmc_num_leapfrogs,
608606
nuts_max_depth = nuts_max_depth,
609607
learn_mass_matrix = learn_mass_matrix,
610-
num_chains = chains, save = save
608+
num_chains = chains
611609
)
612610

613611
if (update_method == "nuts") {
614612
nuts_diag = summarize_nuts_diagnostics(out, nuts_max_depth = nuts_max_depth)
615613
output$nuts_diag = nuts_diag
616614
}
617615

616+
# -------------------------------------------------------------------
617+
# TODO: REMOVE after easybgm >= 0.2.2 is on CRAN
618+
# Compatibility shim for easybgm <= 0.2.1
619+
# -------------------------------------------------------------------
620+
if ("easybgm" %in% loadedNamespaces()) {
621+
ebgm_version <- utils::packageVersion("easybgm")
622+
if (ebgm_version <= "0.2.1") {
623+
warning("bgms is running in compatibility mode for easybgm (<= 0.2.1). ",
624+
"This will be removed once easybgm is updated on CRAN.")
625+
626+
# Add legacy variables to output
627+
output$arguments$save <- TRUE
628+
if (edge_selection) {
629+
output$indicator <- extract_indicators(output)
630+
}
631+
output$interactions <- extract_pairwise_interactions(output)
632+
output$thresholds <- extract_category_thresholds(output)
633+
}
634+
}
635+
618636
userInterrupt = any(vapply(out, FUN = `[[`, FUN.VALUE = logical(1L), "userInterrupt"))
619637
if (userInterrupt)
620638
warning("Stopped sampling after user interrupt, results are likely uninterpretable.")

R/bgms-package.R

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,55 @@
22
#'
33
#' @description
44
#' The \code{R} package \strong{bgms} provides tools for Bayesian analysis of
5-
#' the ordinal Markov random field, a graphical model describing a network of
6-
#' binary and/or ordinal variables \insertCite{MarsmanVandenBerghHaslbeck_2024}{bgms}.
7-
#' A pseudolikelihood is used to approximate the likelihood of the graphical
8-
#' model, and Markov chain Monte Carlo methods are used to simulate from the
9-
#' corresponding pseudoposterior distribution of the graphical model parameters.
5+
#' the ordinal Markov random field (MRF), a graphical model describing networks
6+
#' of binary and/or ordinal variables \insertCite{MarsmanVandenBerghHaslbeck_2024}{bgms}.
7+
#' The likelihood is approximated via a pseudolikelihood, and Markov chain Monte
8+
#' Carlo (MCMC) methods are used to sample from the corresponding pseudoposterior
9+
#' distribution of model parameters.
1010
#'
11-
#' The \strong{bgm} function can be used for a one-sample design and the
12-
#' \strong{bgmCompare} function can be used for a two-independent-samples design
13-
#' \insertCite{MarsmanWaldorpSekulovskiHaslbeck_2024}{bgms}. Both functions can
14-
#' model the selection of effects. In one-sample designs, the \strong{bgm}
15-
#' function models the presence or absence of edges between pairs of variables
16-
#' in the network. The estimated posterior inclusion probability indicates how
17-
#' plausible it is that a network with an edge between the two corresponding
18-
#' variables produced the observed data, and can be converted into a Bayes
19-
#' factor test for conditional independence.
11+
#' The main entry points are:
12+
#' \itemize{
13+
#' \item \strong{bgm}: estimation in a one-sample design.
14+
#' \item \strong{bgmCompare}: estimation and group comparison in an
15+
#' independent-sample design.
16+
#' }
17+
#'
18+
#' Both functions support Bayesian effect selection with spike-and-slab priors.
19+
#' \itemize{
20+
#' \item In one-sample designs, \code{bgm} models the presence or absence of
21+
#' edges between variables. Posterior inclusion probabilities quantify the
22+
#' plausibility of each edge and can be converted into Bayes factors for
23+
#' conditional independence tests.
2024
#'
21-
#' In two-independent-samples designs, the \strong{bgmCompare} function models
22-
#' the selection of group differences in edge weights and possibly category
23-
#' thresholds. The estimated posterior inclusion probability indicates how
24-
#' plausible it is that graphical models with a difference in the corresponding
25-
#' edge weight or category threshold generated the data at hand, and can be
26-
#' converted to a Bayes factor test for parameter equivalence.
25+
#' \item \code{bgm} can also model communities (clusters) of variables. The
26+
#' posterior distribution of the number of clusters provides evidence for or
27+
#' against clustering \insertCite{SekulovskiEtAl_2025}{bgms}.
2728
#'
28-
#' The \strong{bgms} package offers several tools for analyzing the structure of
29-
#' the MRF:
29+
#' \item In independent-sample designs, \code{bgmCompare} estimates group
30+
#' differences in edge weights and category thresholds. Posterior inclusion
31+
#' probabilities quantify the evidence for differences and can be converted
32+
#' into Bayes factors for parameter equivalence tests
33+
#' \insertCite{MarsmanWaldorpSekulovskiHaslbeck_2024}{bgms}.
34+
#' }
3035
#'
36+
#' @section Tools:
37+
#' The package also provides:
3138
#' \enumerate{
32-
#' \item Simulate response data from the MRF using the Gibbs sampler.
33-
#' \itemize{
34-
#' \item Simulate \code{\link{mrfSampler}}.
35-
#' }
36-
#
37-
#' \item Estimate the posterior distribution of the MRF's parameters and
38-
#' possibly its network structure in one-sample designs.
39-
#' \itemize{
40-
#' \item Bayesian estimation or Bayesian edge selection with \code{\link{bgm}}.
41-
#' }
42-
#'
43-
#' \item Estimate the posterior distribution of the MRF's parameters in a
44-
#' two-independent-sample design, and possibly perform selection on group
45-
#' differences in MRF parameters.
46-
#' \itemize{
47-
#' \item Bayesian estimation or Bayesian difference selection with \code{\link{bgmCompare}}.
48-
#' }
39+
#' \item Simulation of response data from MRFs with a Gibbs sampler
40+
#' (\code{\link{mrfSampler}}).
41+
#' \item Posterior estimation and edge selection in one-sample designs
42+
#' (\code{\link{bgm}}).
43+
#' \item Posterior estimation and group-difference selection in
44+
#' independent-sample designs (\code{\link{bgmCompare}}).
4945
#' }
5046
#'
5147
#' @section Vignettes:
5248
#' For tutorials and worked examples, see:
5349
#' \itemize{
54-
#' \item \code{vignette("intro", package = "bgms")} for a getting started guide.
55-
#' \item \code{vignette("comparison", package = "bgms")} for model comparison.
56-
#' \item \code{vignette("diagnostics", package = "bgms")} for diagnostics and spike-and-slab summaries.
50+
#' \item \code{vignette("intro", package = "bgms")} — Getting started.
51+
#' \item \code{vignette("comparison", package = "bgms")} — Model comparison.
52+
#' \item \code{vignette("diagnostics", package = "bgms")} — Diagnostics and
53+
#' spike-and-slab summaries.
5754
#' }
5855
#'
5956
#' @docType package

R/output_utils.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ prepare_output_bgm = function(
44
na_action, na_impute, edge_selection, edge_prior, inclusion_probability,
55
beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda,
66
variable_type, update_method, target_accept, hmc_num_leapfrogs,
7-
nuts_max_depth, learn_mass_matrix, num_chains, save
7+
nuts_max_depth, learn_mass_matrix, num_chains
88
) {
99
arguments = list(
1010
prepared_data = x,
@@ -34,8 +34,7 @@ prepare_output_bgm = function(
3434
num_chains = num_chains,
3535
num_categories = num_categories,
3636
data_columnnames = data_columnnames,
37-
no_variables = ncol(x), #backwards compatibility easybgm
38-
save = save #backwards compatibility easybgm
37+
no_variables = ncol(x) #backwards compatibility easybgm
3938
)
4039

4140
num_variables = ncol(x)

man/bgms-package.Rd

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)