% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nugget-clustering.R
\name{Wkmeans}
\alias{Wkmeans}
\title{Weighted k-means (minimises WWCSS)}
\usage{
Wkmeans(x, k, weights = rep(1, nrow(x)), nstart = 10, max_iter = 100)
}
\arguments{
\item{x}{Numeric matrix, observations in rows.}

\item{k}{Number of clusters.}

\item{weights}{Non-negative weight per observation (default all 1).}

\item{nstart}{Number of random restarts (best WWCSS kept).}

\item{max_iter}{Maximum Lloyd iterations per start.}
}
\value{
A list with \code{cluster}, \code{centers} and \code{wwcss}.
}
\description{
k-means in which each observation carries a non-negative weight. Cluster
centres are weighted means and the objective is the Weighted Within-Cluster
Sum of Squares \eqn{\sum_c \sum_{i \in c} w_i \lVert x_i - \mu_c \rVert^2}.
}
\examples{
set.seed(1)
x <- rbind(matrix(rnorm(20 * 3, 0), 20), matrix(rnorm(20 * 3, 5), 20))
Wkmeans(x, k = 2, weights = runif(40, 1, 5))$cluster[1:5]
}
\references{
Dey, T., Duan, Y., Cabrera, J. & Cheng, X. (2025). WCluster:
Clustering and PCA with Weights, and Data Nuggets Clustering.
}
\seealso{
\code{\link{nugget_cluster}}, \code{\link{Whclust}}
}
