permuteMCMC: Relabel MCMC output based on Permutation Matrix

View source: R/permuteMCMC.R

permuteMCMCR Documentation

Relabel MCMC output based on Permutation Matrix

Description

Relabel MCMC output from finite mixture models using the permutations found by some algorithm

Usage

permuteMCMC(x, perms, what = "cols")

Arguments

x

an array of MCMC samples, where the first index has to be equal to the number of posterior samples, S, and the last index equal to the number of latent classes/extreme types, K.

perms

a S times K matrix of permutations needed to transformed the raw MCMC output to the permuted output, e.g., the perms element from running relabelMCMC.

what

one of "rows", "cols," "both", or "matrix." Determines what dimensions are permuted. For two-dimensional arrays with unequal dimensions (i.e., rectangular matrices), the columns are always permuted.

Details

Given a permutation that resolves the label-switching, this function applies the mapping to another object. If the object to permute is a three-dimensional array of dimension S\*N\*K, the function will treat S as the number of posterior draws and will permute either the columns or the rows of the sub-array which is of dimensions N*K. If x is a matrix, the function assumes that nrow(x) == S and will permute the columns. When the what argument is set to "matrix," it is assumed that the entered array is of dimension S\*K\*L\*L, and permutes the whole L\*L matrix across the K classes for each posterior draw.

Value

returns x permuted according to perms


baruuum/relabelKL documentation built on Feb. 1, 2024, 12:23 a.m.