The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

CRAN r-universe R-CMD-check License

Mixture-of-Experts Wishart models

This R-package moewishart provides maximum likelihood estimation (MLE) and Bayesian estimation for the Wishart mixture model and the Wishart mixture-of-experts (MoE-Wishart) model. It implements four different inference algorithms for the two model:

Installation

Install the latest released version from CRAN:

install.packages("moewishart")

Install the latest development version from GitHub:

# library("devtools")
devtools::install_github("zhizuio/moewishart")

Example


Data simulation from a MoE-Wishart model:

1. Working model: Bayesian MoE-Wishart model

library(moewishart)

n <- 200 # number of subjects
p <- 2 # dimension of covariance matrix
set.seed(123) # fix coefficients of underlying MoE model
Xq <- 3
K <- 3
betas <- matrix(runif(Xq * K, -2, 2), nrow = Xq, ncol = K)
betas[, K] <- 0

# simulate data
dat <- simData(n, p,
  Xq = 3, K = 3, betas = betas,
  pis = c(0.35, 0.40, 0.25),
  nus = c(8, 12, 3)
)

# fit Bayesian MoE-Wishart model
set.seed(123)
fit <- moewishart(
  dat$S,
  X = cbind(1, dat$X), K = 3,
  mh_sigma = c(0.2, 0.1, 0.2), # RW-MH variances (length K)
  mh_beta = c(0.3, 0.3), # RW-MH variances (length K-1)
  niter = 3000, burnin = 1000
)


Posterior means for degrees of freedom (DoF) of Wishart distributions:

burnin <- 1000
nu_mcmc <- fit$nu[-c(1:burnin), ]
colMeans(nu_mcmc)
#> [1]  8.574911 14.397351  3.310689


True DoF:

dat$nu # true nu
#> [1]  8 12  3


Posterior means for scale matrices of Wishart distributions:

MoE_Sigma <- Reduce("+", fit$Sigma) / length(fit$Sigma)
MoE_Sigma
#> , , 1
#> 
#>           [,1]      [,2]
#> [1,] 0.5197160 0.2103881
#> [2,] 0.2103881 0.7470847
#> 
#> , , 2
#> 
#>           [,1]      [,2]
#> [1,] 1.7637949 0.5540576
#> [2,] 0.5540576 1.3244947
#> 
#> , , 3
#> 
#>            [,1]       [,2]
#> [1,]  4.1115070 -0.1267705
#> [2,] -0.1267705  3.0385263


Posterior means for gating coefficients:

beta_mcmc <- fit$Beta_samples[-c(1:burnin), , ]
apply(beta_mcmc, c(2, 3), mean)
#>            [,1]        [,2] [,3]
#> [1,] -0.3656861 -0.08024419    0
#> [2,] -0.9526224  2.24956385    0
#> [3,]  1.7609922  2.40287152    0
#> [4,] -0.4953755 -2.56072719    0

2. Working model: Bayesian Wishart mixture model

# fit Bayesian Wishart mixture model
set.seed(123)
fit2 <- mixturewishart(
  dat$S,
  K = 3,
  mh_sigma = c(0.2, 0.1, 0.2), # RW-MH variances
  niter = 3000, burnin = 1000
)


Posterior means for subpopulation probabilities:

colMeans(fit2$pi[-c(1:burnin), ])
#> [1] 0.2690425 0.5088864 0.2220712


Posterior means for DoF of Wishart distributions:

colMeans(fit2$nu[-c(1:burnin), ])
#> [1]  7.986113 12.153338  3.284252

3. Working model: MoE-Wishart model via EM algorithm

# fit MoE-Wishart model via EM alg.
set.seed(123)
fit3 <- moewishart(
  dat$S,
  X = cbind(1, dat$X), K = 3,
  method = "em",
  niter = 3000
)


EM estimates for DoF of Wishart distributions:

fit3$nu
#> [1]  7.515417 13.987158  3.274665


EM estimates for Wishart scale matrices:

fit3$Sigma
#> [[1]]
#>           [,1]      [,2]
#> [1,] 0.5591113 0.2324429
#> [2,] 0.2324429 0.8148737
#> 
#> [[2]]
#>           [,1]      [,2]
#> [1,] 1.7665723 0.5567668
#> [2,] 0.5567668 1.3336367
#> 
#> [[3]]
#>            [,1]       [,2]
#> [1,]  4.3139885 -0.1886288
#> [2,] -0.1886288  3.0983710


EM estimates for gating coefficients:

fit3$Beta
#>             comp1      comp2 comp3
#> [1,] -0.006270492  0.1302039     0
#> [2,] -0.798302303  2.0340525     0
#> [3,]  1.598530103  2.2399293     0
#> [4,] -0.510585695 -2.3465248     0

4. Working model: Wishart mixture model via EM algorithm

# fit Wishart mixture model via EM alg.
set.seed(123)
fit4 <- mixturewishart(
  dat$S,
  K = 3,
  method = "em",
  niter = 3000
)


EM estimates for DoF of Wishart distributions:

fit4$nu
#> [1]  2.995383  7.682819 11.309040


EM estimate for Wishart scale matrices:

fit4$Sigma
#> [[1]]
#>           [,1]     [,2]
#> [1,]  4.048859 -1.10103
#> [2,] -1.101030  2.79641
#> 
#> [[2]]
#>           [,1]      [,2]
#> [1,] 0.5582012 0.2515063
#> [2,] 0.2515063 0.8151752
#> 
#> [[3]]
#>           [,1]      [,2]
#> [1,] 2.0930529 0.6273737
#> [2,] 0.6273737 1.5706730

Reference

Mai TT, Zhao Z (2026). Mixture-of-experts Wishart model for covariance matrices with an application to Cancer drug screening. arXiv:2602.13888.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.