Skip to content

Commit 51ef241

Browse files
Update to print summary(fit)$indicator: NAs are suppressed and an explanatory note is added to the print table.
1 parent 3e4646f commit 51ef241

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

R/bgmcompare-methods.r

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ print.bgmCompare = function(x, ...) {
1414
prior_msg = switch(
1515
as.character(arguments$difference_prior),
1616
"Bernoulli" = "Bayesian Difference Selection (Bernoulli prior on inclusion)",
17-
"Beta-Bernoulli" = "Bayesian Difference Selection (BetaBernoulli prior on inclusion)",
17+
"Beta-Bernoulli" = "Bayesian Difference Selection (Beta-Bernoulli prior on inclusion)",
1818
"Bayesian Difference Selection"
1919
)
2020
cat(prior_msg, "\n")
@@ -96,7 +96,6 @@ summary.bgmCompare = function(object, ...) {
9696
}
9797

9898

99-
#' @export
10099
#' @export
101100
print.summary.bgmCompare = function(x, digits = 3, ...) {
102101
cat("Posterior summaries from Bayesian grouped MRF estimation (bgmCompare):\n\n")
@@ -127,12 +126,32 @@ print.summary.bgmCompare = function(x, digits = 3, ...) {
127126

128127
if (!is.null(x$indicator)) {
129128
cat("Inclusion probabilities:\n")
130-
print_df(x$indicator, digits)
129+
ind <- head(x$indicator, 6)
130+
131+
# round only numeric columns
132+
ind[] <- lapply(ind, function(col) {
133+
if (is.numeric(col)) {
134+
round(col, digits)
135+
} else {
136+
col
137+
}
138+
})
139+
140+
# replace NA with empty string for printing
141+
ind[] <- lapply(ind, function(col) {
142+
ifelse(is.na(col), "", col)
143+
})
144+
145+
print(ind, row.names = FALSE)
131146
if (nrow(x$indicator) > 6)
132147
cat("... (use `summary(fit)$indicator` to see full output)\n")
133148
cat("\n")
149+
cat("Note: NA values are suppressed in the print table. They occur when an indicator\n")
150+
cat("was constant (all 0 or all 1) across all iterations, so sd/mcse/n_eff/Rhat\n")
151+
cat("are undefined; `summary(fit)$indicator` still contains the NA values.\n\n")
134152
}
135153

154+
136155
if (!is.null(x$main_diff)) {
137156
cat("Group differences (main effects):\n")
138157
print_df(x$main_diff, digits)
@@ -166,13 +185,13 @@ print.summary.bgmCompare = function(x, digits = 3, ...) {
166185
#' @return A list with components:
167186
#' \describe{
168187
#' \item{main_effects_raw}{Posterior means of the raw main-effect parameters
169-
#' (variables × [baseline + differences]).}
188+
#' (variables x [baseline + differences]).}
170189
#' \item{pairwise_effects_raw}{Posterior means of the raw pairwise-effect parameters
171-
#' (pairs × [baseline + differences]).}
190+
#' (pairs x [baseline + differences]).}
172191
#' \item{main_effects_groups}{Posterior means of group-specific main effects
173-
#' (variables × groups), computed as baseline plus projected differences.}
192+
#' (variables x groups), computed as baseline plus projected differences.}
174193
#' \item{pairwise_effects_groups}{Posterior means of group-specific pairwise effects
175-
#' (pairs × groups), computed as baseline plus projected differences.}
194+
#' (pairs x groups), computed as baseline plus projected differences.}
176195
#' \item{indicators}{Posterior mean inclusion probabilities as a symmetric matrix,
177196
#' with diagonals corresponding to main effects and off-diagonals to pairwise effects.}
178197
#' }

R/bgms-methods.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,15 @@ print.summary.bgms <- function(x, digits = 3, ...) {
107107

108108
if (!is.null(x$indicator)) {
109109
cat("Inclusion probabilities:\n")
110-
print(round(head(x$indicator, 6), digits = digits))
111-
if (nrow(x$indicator) > 6) cat("... (use `summary(fit)$indicator` to see full output)\n")
110+
ind <- head(x$indicator, 6)
111+
ind[] <- lapply(ind, function(col) ifelse(is.na(col), "", round(col, digits)))
112+
print(ind, row.names = FALSE)
113+
if (nrow(x$indicator) > 6)
114+
cat("... (use `summary(fit)$indicator` to see full output)\n")
112115
cat("\n")
116+
cat("Note: NA values are suppressed in the print table. They occur when an indicator\n")
117+
cat("was constant (all 0 or all 1) across all iterations, so sd/mcse/n_eff/Rhat\n")
118+
cat("are undefined; `summary(fit)$indicator` still contains the NA values.\n\n")
113119
}
114120

115121
if (!is.null(x$pairwise_allocations)) {

0 commit comments

Comments
 (0)