Learn R Programming

FactoClass (version 1.0.9)

kmeansW: K-means with Weights of the Elements

Description

It is a modification of kmeans Hartigan-Wong algorithm to consider the weight of the elements to classify.

Usage

kmeansW(x, centers, weight = rep(1,nrow(x)),
        iter.max = 10, nstart = 1)

Arguments

x
A numeric vector, matrix or data frame.
centers
Either the number of clusters or a set of initial (distinct) cluster centres. If a number, a random set of (distinct) rows in x is chosen as the initial centres.
weight
weight of the elements of x. by default the same.
iter.max
The maximum number of iterations allowed.
nstart
If centers is a number, how many random sets should be chosen?

Value

  • object of class FactoClass.tex with the following characteristics:
  • clustervector indicating the cluster of each element.
  • ...

Details

With the 'Hartigan-Wong' algorithm, this function performs the K-means clustering diminishing inertia intra classes. In this version the Fortran code kmnsW.f was changed by C++ code kmeanw.cc programed by Camilo Jose Torres, modifing C code programed by Burkardt.

References

Hartigan, J. A. and Wong, M. A. (1979). A K-means clustering algorithm. Applied Statistics 28, 100--108. Burkardt, J. (2008). ASA136 The K-Means Algorithm. http://people.sc.fsu.edu/~burkardt/cpp_src/asa136/asa136.html

Examples

Run this code
data(Bogota)
 ac.bog <- Bogota[-1]
 il.bog <- Bogota[ 1]
 
 acs <- dudi.coa( ac.bog, nf=6 , scannf = FALSE )
 
 kmeansW( acs$li, 7, acs$lw )

Run the code above in your browser using DataLab