stepFlexclust: Run Flexclust Algorithms Repeatedly

Description Usage Arguments Details Author(s) Examples

View source: R/stepflexclust.R

Description

Runs clustering algorithms repeatedly for different numbers of clusters and returns the minimum within cluster distance solution for each.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
stepFlexclust(x, k, nrep=3, verbose=TRUE, FUN = kcca, drop=TRUE,
              group=NULL, simple=FALSE, save.data=FALSE, seed=NULL,
              multicore=TRUE, ...)

stepcclust(...)

## S4 method for signature 'stepFlexclust,missing'
plot(x, y,
  type=c("barplot", "lines"), totaldist=NULL,
  xlab=NULL, ylab=NULL, ...)

## S4 method for signature 'stepFlexclust'
getModel(object, which=1)

Arguments

x, ...

Passed to kcca or cclust.

k

A vector of integers passed in turn to the k argument of kcca

nrep

For each value of k run kcca nrep times and keep only the best solution.

FUN

Cluster function to use, typically kcca or cclust.

verbose

If TRUE, show progress information during computations.

drop

If TRUE and K is of length 1, then a single cluster object is returned instead of a "stepFlexclust" object.

group

An optional grouping vector for the data, see kcca for details.

simple

Return an object of class "kccasimple"?

save.data

Save a copy of x in the return object?

seed

If not NULL, a call to set.seed() is made before any clustering is done.

multicore

If TRUE, use mclapply() from package parallel for parallel processing.

y

Not used.

type

Create a barplot or lines plot.

totaldist

Include value for 1-cluster solution in plot? Default is TRUE if K contains 2, else FALSE.

xlab, ylab

Graphical parameters.

object

Object of class "stepFlexclust".

which

Number of model to get. If character, interpreted as number of clusters.

Details

stepcclust is a simple wrapper for stepFlexclust(...,FUN=cclust).

Author(s)

Friedrich Leisch

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
data("Nclus")
plot(Nclus)

## multicore off for CRAN checks
cl1 <- stepFlexclust(Nclus, k=2:7, FUN=cclust, multicore=FALSE)
cl1

plot(cl1)

# two ways to do the same:
getModel(cl1, 4)
cl1[[4]]

opar <- par("mfrow")
par(mfrow=c(2, 2))
for(k in 3:6){
  image(getModel(cl1, as.character(k)), data=Nclus)
  title(main=paste(k, "clusters"))
}
par(opar)

Example output

Loading required package: grid
Loading required package: lattice
Loading required package: modeltools
Loading required package: stats4
2 : * * *
3 : * * *
4 : * * *
5 : * * *
6 : * * *
7 : * * *
stepFlexclust object of family 'kmeans' 

call:
stepFlexclust(x = Nclus, k = 2:7, FUN = cclust, multicore = FALSE)

  iter converged   distsum
1   NA        NA 2267.8483
2    9      TRUE 1612.3310
3    7      TRUE 1208.0562
4    6      TRUE  742.5601
5   16      TRUE  656.6083
6   12      TRUE  599.6147
7   16      TRUE  571.2330
kcca object of family 'kmeans' 

call:
stepFlexclust(x = Nclus, k = 5L, FUN = cclust, multicore = FALSE)

cluster sizes:

  1   2   3   4   5 
145 103  99 106  97 

kcca object of family 'kmeans' 

call:
stepFlexclust(x = Nclus, k = 5L, FUN = cclust, multicore = FALSE)

cluster sizes:

  1   2   3   4   5 
145 103  99 106  97 

NULL

flexclust documentation built on May 2, 2019, 10:59 a.m.