I am doing Gaussian mixture models. I have done kmeans on the dataset and I want to use the means, variances and the size for the initial parameters for the em algorithm in R. I found that the parameters is a list of 3 and I tried to do the same thing but it gives me the following error :
Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL'
My code
l <- kmeans(iris[,-5],centers=3)
pi <- l$size/length(iris[,1])
my <- t(l$centers)
sig <- vector("list", 3)
new <- as.data.frame(cbind(iris[,-5],l$cluster))
for (i in 1:3) {
subdata<-subset(new[,1:4],new[,5]==i);
sig[[i]]<-cov(subdata)
}
par <- vector("list",3)
par[[1]] <- pi; par[[2]] <- my; par[[3]] <- sig
kk <- em(modelName = msEst$modelName, data = iris[,-5],parameters = par)
Can someone please tell how should I assign the kmeans results as initial parameters?