Learn R Programming

batchmix (version 2.2.1)

getSampledClusterMeans: Get sampled cluster means

Description

Given an array of sampled cluster means from the ``mixtureModel`` function, acquire a tidy version ready for ``ggplot2`` use.

Usage

getSampledClusterMeans(
  sampled_cluster_means,
  K = dim(sampled_cluster_means)[2],
  P = dim(sampled_cluster_means)[1],
  R = dim(sampled_cluster_means)[3],
  thin = 1
)

Value

A data.frame of three columns; the parameter, the sampled value and the iteration.

Arguments

sampled_cluster_means

A 3D array of sampled cluster means.

K

The number of clusters present. Defaults to the number of columns in the batch mean matrix from the first sample.

P

The dimension of the batch mean shifts. Defaults to the number of rows in the batch mean matrix from the first sample.

R

The number of iterations run. Defaults to the number of slices in the sampled batch mean array.

thin

The thinning factor of the sampler. Defaults to 1.

Examples

Run this code

# Data in matrix format
X <- matrix(c(rnorm(100, 0, 1), rnorm(100, 3, 1)), ncol = 2, byrow = TRUE)

# Observed batches represented by integers
batch_vec <- sample(seq(1, 5), size = 100, replace = TRUE)

# MCMC iterations (this is too low for real use)
R <- 100
thin <- 5

# MCMC samples
samples <- runBatchMix(X, R, thin, batch_vec, "MVN")

batch_shift_df <- getSampledClusterMeans(samples$means, R = R, thin = thin)

Run the code above in your browser using DataLab