Skip to contents

Groups adjacent values into clusters if their difference is less than a specified threshold, and computes the mean and total weight for each cluster.

Usage

ClusterAdjacent(values, weights, threshold = 0.01)

Arguments

values

Numeric vector of values to cluster (e.g., means from GMM components).

weights

Numeric vector of weights corresponding to values.

threshold

Numeric value specifying the maximum allowed difference between adjacent values to be grouped into the same cluster. Default is 0.01.

Value

A list with two elements:

means

Numeric vector of cluster means.

weights

Numeric vector of aggregated cluster weights.

Examples

ClusterAdjacent(c(0.1, 0.11, 0.5), c(0.3, 0.4, 0.3))
#> $means
#> [1] 0.105 0.500
#> 
#> $weights
#> [1] 0.7 0.3
#>