Perform k-means clustering on functional data.
Usage
fkmeans(
fdataobj,
ncl = 2,
metric = metric.lp,
dfunc = func.trim.FM,
max.iter = 100,
par.metric = NULL,
par.dfunc = list(trim = 0.05),
method = "sample",
cluster.size = 5,
draw = TRUE,
...
)Arguments
- fdataobj
fdataclass object.- ncl
See details section.
- metric
Metric function, by default
metric.lp.- dfunc
Type of depth measure, by default FM depth.
- max.iter
Maximum number of iterations for the detection of centers.
- par.metric
List of arguments to pass to the
metricfunction.- par.dfunc
List of arguments to pass to the
dfuncfunction .- method
Method for selecting initial centers. If
method="Sample" (by default) takesntimes a random selection by thenclcenters. Thenclcurves with greater distance are the initial centers. Ifmethod="Exact" calculated all combinations (if < 1e+6) ofnclcenters. Thenclcurves with greater distance are the initial centers (this method may be too slow).- cluster.size
Minimum cluster size (by default is 5). If a cluster has fewer curves, it is eliminated and the process is continued with a less cluster.
- draw
=TRUE, draw the curves in the color of the centers.
- ...
Further arguments passed to or from other methods.
Details
The method searches the locations around which are grouped data (for a
predetermined number of groups).
If ncl=NULL, randomizes the initial centers, ncl=2 using
kmeans.center.ini function.
If ncl is an integer,
indicating the number of groups to classify,
are selected ncl
initial centers using kmeans.center.ini function.
If ncl is
a vector of integers, indicating the position of the initial centers with
length(ncl) equal to number of groups.
If ncl is a
fdata class objecct, ncl are the initial centers curves with
nrow(ncl) number of groups.
References
Hartigan, J. A. and Wong, M. A. (1979). A K-means clustering algorithm. Applied Statistics 28, 100 \-108.
See also
See Also generic kmeans function.
Author
Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@udc.es
Examples
if (FALSE) { # \dontrun{
library(fda.usc)
data(phoneme)
ind <- c(1:50,101:150,201:250)
clas <- as.numeric(phoneme$classlearn[ind])
fdataobj <- phoneme$learn[ind,]
# Unsupervised classification
out.fd1 <- fkmeans(fdataobj,ncl=3,draw=TRUE)
out.fd2 <- fkmeans(fdataobj,ncl=3,draw=TRUE,method="exact")
# Different Depth function
ind2 <- c(17,77,126)
out.fd3 <- fkmeans(fdataobj,ncl=fdataobj[ind2,],draw=FALSE,
dfunc =func.trim.FM,par.dfunc=list(trim=0.1))
out.fd4 <- fkmeans(fdataobj, ncl=fdataobj[ind2,],
draw=FALSE, dfunc = func.med.FM)
table(clas,out.fd1$cluster )
table(clas,out.fd4$cluster )
} # }