This function updates the class covariances (independent from the other classes).
update_Omega(beta, b, z, m, nu, Theta)
Arguments
beta: The matrix of the decision-maker specific coefficient vectors of dimension P_r x N. Set to NA if P_r = 0.
b: The matrix of class means as columns of dimension P_r x C. Set to NA if P_r = 0.
z: The vector of the allocation variables of length N. Set to NA if P_r = 0.
m: The vector of class sizes of length C.
nu: The degrees of freedom (a natural number greater than P_r) of the Inverse Wishart prior for each Omega_c. Per default, nu = P_r + 2.
Theta: The scale matrix of dimension P_r x P_r of the Inverse Wishart prior for each Omega_c. Per default, Theta = diag(P_r).
Returns
A matrix of updated covariance matrices for each class in columns.
Details
The following holds independently for each class c. Let Ωc be the covariance matrix of class number c. A priori, we assume that Ωc is inverse Wishart distributed with ν degrees of freedom and scale matrix Θ. Let (βn)zn=c be the collection of βn that are currently allocated to class c, mc the size of class c, and bc the class mean vector. Due to the conjugacy of the prior, the posterior Pr(Ωc∣(βn)zn=c) follows an inverted Wishart distribution with ν+mc degrees of freedom and scale matrix Θ−1+∑n(βn−bc)(βn−bc)′, where the product is over the values n for which zn=c holds.
Examples
### N = 100 decider, P_r = 2 random coefficients, and C = 2 latent classesN <-100b <- cbind(c(0,0),c(1,1))(Omega_true <- matrix(c(1,0.3,0.3,0.5,1,-0.3,-0.3,0.8), ncol=2))z <- c(rep(1,N/2),rep(2,N/2))m <- as.numeric(table(z))beta <- sapply(z,function(z) rmvnorm(b[,z], matrix(Omega_true[,z],2,2)))### degrees of freedom and scale matrix for the Wishart priornu <-1Theta <- diag(2)### updated class covariance matrices (in columns)update_Omega(beta = beta, b = b, z = z, m = m, nu = nu, Theta = Theta)