sample_pos_z: sample_pos_z

Description Usage Arguments Value Examples

Description

The function sample_pos_z is used to update/sample the indicators z_1, ..., z_n. The core function is the basic sample function. The component probability equals a density evaluated at the latent variable coexisting with z and a probability that is associated with the (latent) true prior of these component probability.

Usage

1
sample_pos_z(K, ord, pvec)

Arguments

K

a value that gives the total category that z varies from.

ord

a matrix with (i,j) component equals the prespecified density evaluated at the latent variable coexisting with z_i.

pvec

a vector of probabilities that is associated with the (latent) true prior of these component probability.

Value

A vector containing the posterior samples z_1,...,z_n.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set.seed(123)
N <- 500
K <- 3
alpha <- c(2.928, 2.979, 2.754)
beta <- c(0.124, 0.238, 0.045)
p <- c(0.069, 0.758, 0.173)
theta <-  rgamma(N, shape=2.6, rate=0.3)
d.ordinates <- matrix(0, nrow=N, ncol=K)
for(jj in 1:K){
    d.ordinates[,jj] <- dgamma(theta, shape=alpha[jj], rate=beta[jj])
}
z <- sample_pos_z(1:K, d.ordinates, p) 

tamustatsy/bcdd documentation built on May 7, 2019, 9:39 a.m.