# What function of distance for the questionnaire data?

I have data from questionnaire from school. First question is study program (only 2 programs) and next 35 questions are various questions (influence of friends etc.)

Possible answers for 35 questions are "definitely yes", "mostly yes", "mostly no" and "definitely no". Some of data contains missing values.

I want to do hierarchical clustering in R (hclust). First of all I merged answers "definitely yes" with "mostly yes" and "mostly no" and "definitely no". So now I have "yes", "no" and missing values.

For "yes" I assigned value 1, for "no" -1 and for missing values 0.

My questions are:

Is my categorization of data good?

What function of distance is suitable for this type of data? hclust in R usually use Euclidean and Manhattan distance, but I think these distances are not suitable for my type of data (because of missing values).

Thanks

• Setting missing values to 0 will result in them being similar to other missing values and even to yes and no. One possibility to approach this is to define a similarity function which will assign a low similarity (per dimension) to every comparison where a missing value is involved.
– user14071
Oct 8, 2012 at 12:21
• Why really did you roughened your 4-point scale into 2-point? Oct 8, 2012 at 12:42
• Actually, for simplicity. But now I know, that I will consider 4-point. Oct 8, 2012 at 13:04
• Using 0 for unknown will really screw you. Because it is 'more' similar than if they had answered the exact opposite! The most central object will be the one that answered not a single question. Oct 8, 2012 at 13:09

Note that on binary data, there is little difference between the various distance functions.

For example Euclidean and Manhattan distance: Since $(\pm 1)^2 = 1 = |\pm 1|$ and $0^2=0=|0|$, the Euclidean and Manhattan distances will produce the exact same ranking.

So you might want to look into set metrics, starting with Hamming, Jaccard, Tanimoto etc.

As for handling missing values, 0 will not do the trick. You really should treat the value as unknown/missing, not "half positive, half negative".

I'd suggest that you don't completely drop the distinction, but instead assign the values "0, 0.2, 0.8, 1" to the four choices, and N/A to missing values.

Then for distance functions, you can probably just use Manhattan or one of the set based, but make sure to add proper handling of missing values - for example by ignoring that attribute altogether.

The worst case then is that two records do not have any answered question in common. Say one answered only the first question, the other answered only the second. You just cannot compare these two! With your current approach (assigning 0 to "not answered"), you make these two almost identical (which the aren't, IMHO)!

A naive but probably quite reasonable approach would be to just use $$\frac{\text{Number of questions answered with the same trend}}{\text{Number of questions answered by both users}}$$ or $$\frac{\text{Number of questions answered with the same trend}}{\max\left\{\#\text{Q. answered by first user},\#\text{Q. answered by second user}\right\}}$$

• I assign the values "0, 0.2, 0.8, 1" to the four choices and NA to missing values. I did some measumerement on it and it seems to be suitable. Euclidean and Manhattan distance seem to be same on this. Now I'm trying to do hierarchical clustering. For distance function I use dist in R (which exluding missing values). I'm not sure which method of hierarchical clustering I should used. I mean single, complete, average or ward. Each method gives different results. Oct 15, 2012 at 11:31
• Yes, and this is good. Clustering methods are explorative. If they would always give you the same results, you wouldn't need different methods. They are meant to discover different clusters. Oct 15, 2012 at 13:26
• Yes, I know. But how do I know the best method? Oct 18, 2012 at 15:21
• There is no objective "best". It's very subjective. Either it works for you, or it does not find something new. Oct 18, 2012 at 15:49
• Yes, when I use single, complete, average or ward linkage method, each method gives different dendrogram. And now I dont know which dendrogram is most suitable for conclude results. Oct 18, 2012 at 17:11

First question should not be used in clustering, since it is only assignment to any student program.

I think that it is not a good idea to transform original variables to binary type (loss of information). You can use original format with missing values and 4 point scale.

Note that R is capable to compute distance also with missing values (using interpolation technique) so do not be afraid and use standard dist() function.