demo/ManlyKmeans2.R

set.seed(123)

#Use iris dataset
K <- 3; p <- 4
X <- as.matrix(iris[,-5])
n <- dim(X)[1]

#Use k-means clustering result as the initialization
#All skewness parameters set to be 0.1
M.K <- kmeans(X, K)
id.km <- M.K$cluster
la <- matrix(0.1, K, p)

#Calculate the following parameters based on the k-means id: Mu, S
nk <- sapply(1:K, function(k){ sum(id.km == k)})
Mu <- t(sapply(1:K, function(k){ colMeans(X[id.km == k,]) }))
S <- M.K$withinss / nk / p

#Run the Manly K-means algorithm with Manly mixture model
M.MK2 <- Manly.Kmeans(X, la = la, Mu = Mu, S = S)
print(M.MK2)

Try the ManlyMix package in your browser

Any scripts or data that you put into this service are public.

ManlyMix documentation built on April 29, 2023, 9:17 a.m.