update_Omega function

Update class covariances

Update class covariances

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 cc. Let Ωc\Omega_c be the covariance matrix of class number c. A priori, we assume that Ωc\Omega_c is inverse Wishart distributed with ν\nu degrees of freedom and scale matrix Θ\Theta. Let (βn)zn=c(\beta_n)_{z_n=c} be the collection of βn\beta_n that are currently allocated to class cc, mcm_c the size of class cc, and bcb_c the class mean vector. Due to the conjugacy of the prior, the posterior Pr(Ωc(βn)zn=c)\Pr(\Omega_c \mid (\beta_n)_{z_n=c}) follows an inverted Wishart distribution with ν+mc\nu + m_c degrees of freedom and scale matrix Θ1+n(βnbc)(βnbc)\Theta^{-1} + \sum_n (\beta_n - b_c)(\beta_n - b_c)', where the product is over the values nn for which zn=cz_n=c holds.

Examples

### N = 100 decider, P_r = 2 random coefficients, and C = 2 latent classes N <- 100 b <- 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 prior nu <- 1 Theta <- diag(2) ### updated class covariance matrices (in columns) update_Omega(beta = beta, b = b, z = z, m = m, nu = nu, Theta = Theta)