# Data in a matrix format
X <- matrix(c(rnorm(100, 0, 1), rnorm(100, 3, 1)), ncol = 2, byrow = TRUE)
# Initial labelling
labels <- c(
rep(1, 10),
sample(c(1, 2), size = 40, replace = TRUE),
rep(2, 10),
sample(c(1, 2), size = 40, replace = TRUE)
)
fixed <- c(rep(1, 10), rep(0, 40), rep(1, 10), rep(0, 40))
# Batch
batch_vec <- sample(seq(1, 5), replace = TRUE, size = 100)
# Density choice
type <- "MVN"
# Sampling parameters
R <- 1000
thin <- 50
# MCMC samples and BIC vector
samples <- batchSemiSupervisedMixtureModel(
X,
R,
thin,
labels,
fixed,
batch_vec,
type
)
# Given an initial value for the parameters
initial_class_means <- matrix(c(1, 1, 3, 4), nrow = 2)
initial_class_covariance <- array(c(1, 0, 0, 1, 1, 0, 0, 1),
dim = c(2, 2, 2)
)
# We can use values from a previous chain
initial_batch_shift <- samples$batch_shift[, , R / thin]
initial_batch_scale <- matrix(
c(1.2, 1.3, 1.7, 1.1, 1.4, 1.3, 1.2, 1.2, 1.1, 2.0),
nrow = 2
)
samples <- batchSemiSupervisedMixtureModel(X,
R,
thin,
labels,
fixed,
batch_vec,
type,
initial_class_means = initial_class_means,
initial_class_covariance = initial_class_covariance,
initial_batch_shift = initial_batch_shift,
initial_batch_scale = initial_batch_scale
)
Run the code above in your browser using DataLab