wmean {WCluster}R Documentation

Cluster Centers for observations with weights

Description

This function computes the weighted cluster centers for a set of cluster assignments provided to a dataset with observational weights.

Usage

wmean(x,cl,w)

Arguments

x

A data matrix (data frame, data table, matrix, etc.) containing only entries of class numeric.

cl

Vector of length nrow(x) of cluster assignments for each observation in the dataset, indicating the cluster to which each observation is allocated. Must be of class integer.

w

Vector of length nrow(x) of weights for each observation in the dataset. Must be of class numeric or integer. If NULL, the default value is a vector of 1 with length nrow(x), i.e., weights equal 1 for all observations.

Details

In this function, the function weighted.mean in the stats package is used to calculate the cluster centers for each cluster with observational weights.

Value

A matrix of cluster centres. Each column is a weighted center for one cluster.

Author(s)

Javier Cabrera, Yajie Duan, Ge Cheng

References

Cherasia, K. E., Cabrera, J., Fernholz, L. T., & Fernholz, R. (2022). Data Nuggets in Supervised Learning. In Robust and Multivariate Statistical Methods: Festschrift in Honor of David E. Tyler (pp. 429-449). Cham: Springer International Publishing.

Beavers, T., Cheng, G., Duan, Y., Cabrera, J., Lubomirski, M., Amaratunga, D., Teigler, J. (2023). Data Nuggets: A Method for Reducing Big Data While Preserving Data Structure (Submitted for Publication)

See Also

Wkmeans

Examples


    require(cluster)
    # The Ruspini data set from the package "cluster""
    x = as.matrix(ruspini)

    # assign random weights to observations
    w = sample(1:10,nrow(x),replace = TRUE)

    # assign random clusters to observations
    cl = sample(1:3,nrow(x),replace = TRUE)

    #output the weighted cluster centers for each cluster under the random cluster assignments
    wmean(x, cl, w)


[Package WCluster version 1.2.0 Index]