R if (nrow(emobj$Mu) != nclass || ncol(emobj$Mu) != p || nrow(emobj$LTSigma) != 错误:需要 TRUE/FALSE 的地方缺少值

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

我在 R 中使用 EMCluster 库时遇到以下错误:

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

这是我写的代码:

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

我正在使用 Iris 数据集。

我的目标是运行 EM 聚类算法并通过绘图等描述我的观察

您需要提供参数,或者您可以初始化EM并提供:

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