Search code examples
rcluster-analysisexpectation-maximization

R Error in if (nrow(emobj$Mu) != nclass || ncol(emobj$Mu) != p || nrow(emobj$LTSigma) != : missing value where TRUE/FALSE needed


I am getting the following error while using the EMCluster library in R:

Error in if (nrow(emobj$Mu) != nclass || ncol(emobj$Mu) != p || nrow(emobj$LTSigma) !=  : 
missing value where TRUE/FALSE needed

This is the code I wrote:

emcluster(iris[,-5], pi = NULL, Mu = NULL, LTSigma = NULL,
      lab = NULL, EMC = .EMC, assign.class = FALSE)

I am using the Iris dataset.

My goal is to run an EM clustering algorithm and describe my observations through plots, etc.


Solution

  • You need to provide the parameters, or you can initialize the EM and provide that:

    library(EMCluster)
    
    emobj <- simple.init(iris[,-5], nclass = 3)
    mdl <- emcluster(iris[,-5], emobj = emobj, assign.class = TRUE)
    
    table(mdl$class,iris$Species)
       
        setosa versicolor virginica
      1      0          0        15
      2      0         50        35
      3     50          0         0