dmrfit: Scalable Bayesian Inference for Discrete Markov Random Fields


dmrfit estimates discrete Markov Random Fields, both Ising models (Ising, 1925) and Ordinal Markov Random Fields (Marsman et al., 2025), through the pseudo-likelihood. It offers a frequentist route, with point estimates from a trust region algorithm and robust standard errors, and a Bayesian route, in which the pseudo-posterior is corrected with coordinate rescaling (CoRe; Arena and Marsman, 2026). Point estimation supports both full network estimation, where all edges are included, and constrained network estimation, where only a specified subset of edges is considered.


Main functionalities

dmrfit(): point estimation and Bayes factors

dmrfit_bayes(): posterior sampling

plot(): plots of both fit objects, made with ggplot2

Both fitting functions return objects with print(), summary(), confint() and plot() methods.


Installation

Install the development version from GitHub:

# remotes::install_github("jupepis/dmrfit")
install.packages("dmrfit", repos = c('https://jupepis.r-universe.dev', 'https://cloud.r-project.org')) # install package via remotes

library(dmrfit) # load the package

Example

library(dmrfit)

# RADS-2 responses of 917 adolescents (25 items, 4 ordered categories). Here the 10 items of two clusters
data(rads2)
clusters <- attr(rads2, "clusters")
items <- names(clusters)[clusters %in% c("Dysphoria", "Anhedonia/Negative Affect")]

# Point estimates, GHW standard errors, likelihood-ratio intervals and Savage-Dickey Bayes factors
fit <- dmrfit(rads2[, items], with_prior = TRUE, savage_dickey = TRUE, lrt_intervals = TRUE)
summary(fit)
confint(fit)

# Posterior sampling from the coordinate-rescaled pseudo-posterior
fit_bayes <- dmrfit_bayes(rads2[, items], nsim = 5000, burnin = 1000)
summary(fit_bayes)

The example uses rads2, data from Ramos-Vera et al. (2023) distributed under the CC BY 4.0 license (see ?rads2).


Plots

plot(fit_bayes, groups = clusters[items])  # network of the included edges, nodes grouped by cluster
plot(fit_bayes, type = "bf")               # evidence for every edge

Network of the included edges of the 10 RADS-2 items, with the nodes grouped by clusterEvidence for every edge of the 10 RADS-2 items, from excluded to included, with the size of the interaction

plot(fit_bayes, type = "density")     # posterior densities of the four largest interactions
plot(fit_bayes, type = "centrality")  # expected influence of every item

Posterior densities of the four largest interactions, with their posterior modes and highest posterior density intervalsExpected influence of the 10 RADS-2 items, with highest posterior density intervals and the posterior probability of being the most central

plot(fit, type = "intervals")  # estimates and likelihood-ratio intervals

Estimates and likelihood-ratio intervals of the thresholds and interactions of the 10 RADS-2 items


Any issues with the package?

Should you encounter errors while using the package, or for reporting any kind of malfunction of the package, you can open an issue in here.

When opening an issue, please, use a descriptive title that clearly states the issue, be as thorough as possible when describing the issue, provide code snippets that can reproduce the issue.


References