dsy109 / mixtools

Tools for Analyzing Finite Mixture Models
18 stars 4 forks source link

Seldom error in mvnormalmixEM #6

Open mariusbommert opened 1 year ago

mariusbommert commented 1 year ago

When using mvnormalmixEM I encountered the error error in qr.solve(a) : singular matrix 'a' in solve. It occurs rather rarely.

The error can be reproduced with the following example:

library(mixtools)

set.seed(6)
rn = rbind(rmvnorm(n = 18, mu = c(0, 0), sigma = diag(2)),  rmvnorm(n = 2, mu = c(3, 3), sigma = diag(2)))
set.seed(17)
mvnormalmixEM(rn)

The error occurs only with certain seeds. Changing the second seed to 1, for example, works fine. Perhaps it would be useful to restart the algorithm when an error occurs.