kmeansStepAIC: stepwise modelselection of k-means cluster using AIC

Description Usage Arguments Author(s) References Examples

View source: R/kmeansStepAIC.R

Description

stepwise modelselection of k-means cluster using AIC

Usage

1
kmeansStepAIC(x, centers = 1, iter.max = 10, nstart = 10, algorithm = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"), trace = FALSE)

Arguments

x
centers
iter.max
nstart
algorithm
trace

Author(s)

Markus Mayer

References

http://sherrytowers.com/2013/10/24/k-means-clustering/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, centers = 1, iter.max = 10, nstart = 10, algorithm = c("Hartigan-Wong", 
    "Lloyd", "Forgy", "MacQueen"), trace = FALSE) 
{
    oldAIC <- kmeansAIC(kmeans(x, centers, iter.max, nstart, 
        algorithm, trace))
    centers <- centers + 1
    newAIC <- kmeansAIC(kmeans(x, centers, iter.max, nstart, 
        algorithm, trace))
    while (oldAIC > newAIC) {
        oldAIC <- newAIC
        centers <- centers + 1
        newAIC <- kmeansAIC(kmeans(x, centers, iter.max, nstart, 
            algorithm, trace))
    }
    return(list(AIC = oldAIC, kmeans = kmeans(x, centers = centers - 
        1, iter.max, nstart, algorithm, trace)))
  }

kmeansstep documentation built on May 2, 2019, 5 p.m.