# Cluster analysis on weighted survey data with continuous and categorical variables

I am trying to perform cluster analysis on survey data where each respondent has answered several questions, some of which have categorical answers ("blue" "pink" "green" etc) and some of which have scale answers (rating from 1 to 10 etc).

My problem is that certain age groups were over-sampled and I need to weight the data collected in order to accurately reflect the current population.

Will it make a difference if I do the cluster analysis on the weighted data, and if so, how do I do cluster analysis on the weighted data?

Any advice would be much appreciated!

Thanks Emma

• If you cluster respondents, not variables, weighting of respondents has (quite logically) no effect on the results of most clustering methods; moreover, most methods will just ignore your weighting or force you to switch weighting off. – ttnphns Mar 19 '13 at 15:27
• Also note that depending on the complexity of the stratification, you may require Taylor Series Linearization, maybe. This is quite common if using data from a population-based survey. – Behacad Mar 19 '13 at 19:41
• If the survey oversampled subjects with respect to covariates that you want in the model, then the model provides proper conditional estimates and you do not need to take sample weights into account. Sample weights are of interest when estimating population quantities (e.g., population mean family income) where you want to average over a heterogeneous collection of individuals where some subsets of the sample are underrepresented in the sample. – Frank Harrell May 19 '13 at 13:42
• Which clustering model you use? – user31264 Oct 17 '13 at 4:43

Some cluster algorithms can use case weights. At least, "average" (also called UPGMA) or "Ward" clustering methods can use weights. If available, you should use those weights to get non biased results. In R, you can specify weights using the member argument of the "hclust" function (in base R). The WeightedCluster library also provides some functions (such as partionning around medoids PAM and clustering quality measure) for clustering weighted data.

You can mix different types of variable (i.e. nominal, metric, ...) using the "gower" distance. In R, this distance is available in the "cluster" library using the "daisy" function.

daisy(..., metric="gower")


?daisy
?hclust