mrfSampler {bgms}R Documentation

Sample states of the ordinal MRF

Description

This function samples states from the ordinal MRF using a Gibbs sampler. The Gibbs sampler is initiated with random values from the response options, after which it proceeds by simulating states for each node from a logistic model using the other node states as predictor variables.

Usage

mrfSampler(
  no_states,
  no_nodes,
  no_categories,
  interactions,
  thresholds,
  iter = 1000
)

Arguments

no_states

The number of states of the ordinal MRF to be generated.

no_nodes

The number of nodes in the ordinal MRF.

no_categories

Either a positive integer or a vector of positive integers of length no_nodes. The number of response categories on top of the base category: no_categories = 1 generates binary states.

interactions

A symmetric no_nodes by no_nodes matrix of pairwise interactions. Only its off-diagonal elements are used.

thresholds

A no_nodes by max(no_categories) matrix of category thresholds. The elements in row r indicate the thresholds of node r. If no_categories is a vector, only the first no_categories[r] elements are used in row r.

iter

The number of iterations used by the Gibbs sampler. The function provides the last state of the Gibbs sampler as output. By default set to 1e3.

Value

A no_states by no_nodes matrix of simulated states of the ordinal MRF.

Examples

# Generate responses from a network of five binary and ordinal variables.
no_nodes = 5
no_categories = sample(1:5, size = no_nodes, replace = TRUE)

Interactions = matrix(0, nrow = no_nodes, ncol = no_nodes)
Interactions[2, 1] = Interactions[4, 1] = Interactions[3, 2] =
  Interactions[5, 2] = Interactions[5, 4] = .25
Interactions = Interactions + t(Interactions)
Thresholds = matrix(0, nrow = no_nodes, ncol = max(no_categories))
x = mrfSampler(no_states = 1e3,
               no_nodes = no_nodes,
               no_categories = no_categories,
               interactions = Interactions,
               thresholds = Thresholds)

[Package bgms version 0.1.1 Index]