This function massages the input quaternion time series to feed them into the k-means alignment algorithm for jointly clustering and aligning the input QTS.

## Usage

kmeans(x, k, iter_max = 10, nstart = 1, ...)

# S3 method for default
kmeans(
x,
k,
iter_max = 10,
nstart = 1,
algorithm = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"),
trace = FALSE,
...
)

# S3 method for qts_sample
kmeans(
x,
k = 1,
iter_max = 10,
nstart = 1,
centroid = "mean",
dissimilarity = "l2",
warping = "affine",
...
)

## Arguments

x

Either a numeric matrix of data, or an object that can be coerced to such a matrix (such as a numeric vector or a data frame with all numeric columns) or an object of class qts_sample.

k

An integer value specifying the number of clusters to be look for.

iter_max

An integer value specifying the maximum number of iterations for terminating the k-mean algorithm. Defaults to 10L.

nstart

An integer value specifying the number of random restarts of the algorithm. The higher nstart, the more robust the result. Defaults to 1L.

...

not used.

algorithm

character: may be abbreviated. Note that "Lloyd" and "Forgy" are alternative names for one algorithm.

trace

logical or integer number, currently only used in the default method ("Hartigan-Wong"): if positive (or true), tracing information on the progress of the algorithm is produced. Higher values may produce more tracing information.

centroid

A string specifying which type of centroid should be used when applying kmeans on a QTS sample. Choices are mean and medoid. Defaults to mean.

dissimilarity

A string specifying which type of dissimilarity should be used when applying kmeans on a QTS sample. Choices are l2 and pearson. Defaults to l2.

warping

A string specifying which class of warping functions should be used when applying kmeans on a QTS sample. Choices are none, shift, dilation and affine. Defaults to affine.

## Value

An object of class stats::kmeans if the input x is NOT of class qts_sample. Otherwise, an object of class kma_qts which is effectively a list with three components:

• qts_aligned: An object of class qts_sample storing the sample of aligned QTS;

• qts_centers: A list of objects of class qts representing the centers of the clusters;

• best_kma_result: An object of class fdacluster::kma storing the results of the best k-mean alignment result among all initialization that were tried.

## Examples

res_kma <- kmeans(vespa64\$igp, k = 2)