R Under development (unstable) (2025-07-15 r88411 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## VT::15.01.2020 - this will render the output independent > ## from the version of the package > suppressPackageStartupMessages(library(trimcluster)) > > set.seed(10001) > n1 <-60 > n2 <-60 > n3 <-70 > n0 <-10 > nn <- n1+n2+n3+n0 > pp <- 2 > X <- matrix(rep(0,nn*pp),nrow=nn) > ii <-0 > for (i in 1:n1){ + ii <-ii+1 + X[ii,] <- c(5,-5)+rnorm(2) + } > for (i in 1:n2){ + ii <- ii+1 + X[ii,] <- c(5,5)+rnorm(2)*0.75 + } > for (i in 1:n3){ + ii <- ii+1 + X[ii,] <- c(-5,-5)+rnorm(2)*0.75 + } > for (i in 1:n0){ + ii <- ii+1 + X[ii,] <- rnorm(2)*8 + } > > tkm1 <- trimkmeans(X, k=3, trim=0.1, runs=5, scaling=TRUE) > # runs=5 is used to save computing time. > print(tkm1) * trimmed k-means * trim= 0.1 , k= 3 Classification (trimmed points are indicated by 4 ): [1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 3 3 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 [38] 3 3 3 4 3 3 3 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 [75] 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 [112] 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [149] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [186] 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 Means: X 1 X 2 C 1 -4.948673 -4.978344 C 2 5.125058 5.040808 C 3 5.139695 -5.083246 Trimmed mean squares: 0.04719378 > plot(tkm1, X) > > ## With fixed initial values > set.seed(1) > k <- 3 > means <- X[sample(nrow(X), k), , drop=FALSE] > tkm2 <- trimkmeans(X, k=3, trim=0.1, runs=5, points=means) Warning message: In tkmeans(data, k = k, alpha = trim, scale = scaling, nstart = runs, : If initial mean vectors are specified, 'nstart' should be 1 (otherwise the same initial means are used for all runs) > > ## Univariate data > set.seed(2) > tkm3 <- trimkmeans(X[, 1, drop=FALSE], k=3, trim=0.1, runs=5) > plot(tkm3, X[, 1, drop=FALSE]) > > ## Multivariate data (p > 2) > set.seed(3) > X1 <- as.matrix(iris[, 1:4]) > tkm4 <- trimkmeans(X1, k=3, trim=0.1, runs=5) > plot(tkm4, X1) > > ## use deprecated arguments > try(tkm5 <- trimkmeans(iris[, 1:4], k=3, trim=0.1, runs=5, countmode=100, + printcrit=TRUE, maxit=1000)) Warning messages: 1: In trimkmeans(iris[, 1:4], k = 3, trim = 0.1, runs = 5, countmode = 100, : The parameter 'maxit' is deprecated, please read the help and use the combination of 'niter1', 'niter2', 'nkeep'. 2: In trimkmeans(iris[, 1:4], k = 3, trim = 0.1, runs = 5, countmode = 100, : The parameter 'countmode' is deprecated, please use 'trace'. 3: In trimkmeans(iris[, 1:4], k = 3, trim = 0.1, runs = 5, countmode = 100, : The parameter 'printcrit' is deprecated, please use 'trace'. > > tkmx1 <- trimcluster:::trimkmeans_orig(X, k=3, trim=0.1, runs=3, scaling=TRUE, countmode=10, printcrit=TRUE) Iteration 1 criterion value 0.04719378 Iteration 2 criterion value 0.0472178 Iteration 3 criterion value 0.04719378 > # runs=3 is used to save computing time. > > set.seed(1) > k <- 3 > means <- X[sample(nrow(X), k), , drop=FALSE] > tkmx2 <- trimcluster:::trimkmeans_orig(X, k=3, trim=0.1, runs=3, points=means) > > proc.time() user system elapsed 1.42 0.07 1.48