Learn R Programming

cbass (version 0.1)

sample.z: Draw samples of independent normals (matrix) given previous sample, and maximal values

Description

Draw samples of independent normals (matrix) given previous sample, and maximal values

Usage

sample.z(mu, y, z)

Value

A new sample of n by d matrix of latent random variables

Arguments

mu

n by d matrix of latent means

y

n-length vector of maximal indices

z

n by d matrix of latent random variables

Examples

Run this code
set.seed(1)
n <- 100;  d <- 3
mu <- matrix(rnorm(n*d), n, d)
bound <- qnorm(1/d^(1/(d-1)))
mu[,1] <- bound
z <- mu
z[,-1] <- rnorm(length(mu[,-1]), mu[,-1], 1)
y <- apply(z, 1, which.max)
z.new <- sample.z(mu, y, z)
all(apply(z.new, 1, which.max) == y)

Run the code above in your browser using DataLab