Description Details Disclaimer Author(s) References See Also

This package provides a powerful set of tools for univariate data analysis with guaranteed optimality, efficiency, and reproducibility.
Four problems including univariate *k*-means, *k*-median, *k*-segments, and multi-channel weighted *k*-means are solved with guaranteed optimality and reproducibility. The core algorithm minimizes the (weighted) sum of within-cluster distances using respective metrics. Its advantage over heuristic clustering in efficiency and accuracy is increasingly pronounced as the number of clusters *k* increases. Weighted *k*-means can also optimally segment time series to perform peak calling. An auxiliary function generates histograms that are adaptive to patterns in data.

The Ckmeans.1d.dp algorithm clusters (weighted) univariate data given by a numeric vector *x* into *k* groups by dynamic programming \insertCiteWang2011Ckmeans,song2020wucCkmeans.1d.dp. It guarantees the optimality of clustering—the total of within-cluster sums of squares is always the minimum given the number of clusters *k*. In contrast, heuristic univariate clustering algorithms may be non-optimal or inconsistent from run to run. As non-negative weights are supported, the algorithm can partition a time course using time points as input and corresponding values as weight. Based on an optimal clustering, a function can generate histograms adaptive to patterns in data. The implementation of this algorithm is numerically stable.

A linear time solution. Excluding the time for sorting *x*, the weighted univariate clustering algorithm takes a runtime of *O(kn)* \insertCitesong2020wucCkmeans.1d.dp, linear in both sample size *n* and the number of clusters *k*. The approach was first introduced into version 3.4.9 (not publicly released) on July 16, 2016, using a new divide-and-conquer strategy integrating a previous theoretical result on matrix search \insertCiteaggarwal1987geometricCkmeans.1d.dp and a novel in-place search space reduction method \insertCitesong2020wucCkmeans.1d.dp.

A log-linear time solution. Since version 3.4.6, a divide-and-conquer strategy that is simple to code reduces the runtime from *O(kn^2)* down to *O(kn lg n)* \insertCitesong2020wucCkmeans.1d.dp.

A quadratic time solution. Before version 3.4.6, Ckmeans.1d.dp uses an algorithm that runs in quadratic runtime *O(kn^2)* \insertCiteWang2011CkmeansCkmeans.1d.dp.

A cubic time solution. \insertCiteBellman1973;textualCkmeans.1d.dp first described a general dynamic programming strategy for solving univariate clustering problems with additive optimality measures. The strategy, however, did not address any specific characteristics of the *k*-means problem and its implied general algorithm will have a time complexity of *O(kn^3)* on an input of *n* points.

The space complexity in all cases is *O(kn)*.

This package provides a powerful alternative to heuristic clustering and also new functionality for weighted clustering, segmentation, and peak calling with guaranteed optimality. It is practical for Ckmeans.1d.dp to find a few clusters on millions of sample points with optional weights in seconds using a single core on a typical desktop computer.

Third parties have ported various versions of this package to JavaScript, MATLAB, Python, Ruby, SAS, and Scala.

Package: | Ckmeans.1d.dp |

Type: | Package |

Version: | 4.3.3 |

Initial release version: | 1.0 |

Initial release date: | 2010-10-26 |

License: | LGPL (>= 3) |

The most important function of this package is `Ckmeans.1d.dp`

that implements optimal univariate clustering either weighted or unweighted. It also contains an adaptive histogram function `ahist`

, plotting functions `plot.Ckmeans.1d.dp`

and `plotBIC`

, and a print function `print.Ckmeans.1d.dp`

.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Joe Song, Hua Zhong, and Haizhou Wang

The `kmeans`

function in package stats that implements several heuristic *k*-means algorithms.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.