If I had a vector of weights for each observation
data(iris) wghts <- abs(rnorm(nrow(iris)))
And I had a function that did not accept weights as an argument:
Can I multiply each variable by the weights to get the desired output?
There is a version of kmeans that accepts weights:
library(FactoClass) kmeansW(iris[-5], centers=3, weight=wghts)
But there are aspects of regular
kmeans output that I still want, including
betweenss. And just for learning purposes, Is it possible to just multiply all observations by the weight vector to get the equivalent output?
newdf <- iris[-5] newdf <- lapply(newdf, function(v) v*wghts) kmeans(newdf, centers=3)
Did I successfully "add" the weights by multiplying each variable by the weights or am I missing some aspect of weighted kmeans theory?
In other words, is
kmeans(newdf, centers=3) structurally equivalent to
kmeansW(iris[-5], centers=3, weight=wghts)?