2
$\begingroup$

I have a situation where there are n individuals and p features (variables). I do have their cluster information. Here is an example:

myd <- data.frame (
 sub1 = c(1, "AB", "AB", "BB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub2 = c(1, "AB", "BB", "BB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub3 = c(1, "AB", "BB", "AB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub4 = c(1, "AB", "BB", "AB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub5 = c(1, "AB", "BB", "BB", "AB", "AB", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub6 = c(1, "AB", "BB", "BB", "BB", "AA", "AB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub7 = c(2, "AA", "AA", "BB", "AB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub8 = c(2, "AB", "AA", "AB", "AB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub9 = c(2, "AA", "AA", "BB", "AB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub10 = c(2, "AB", "AA", "BB", "AB", "AA", "BB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub11 = c(2, "AA", "AA", "BB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB"),
sub12 = c(2, "AA", "AB", "BB", "BB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub13 = c(3, "AB", "AB", "AB", "AB", "AB", "BB", "AB", "AA", "AB", "AA", "AB", "BB"),
sub14 = c(3, "AB", "BB", "BB", "AB", "AB", "BB", "AB", "AA", "AB", "AA", "AB", "BB"),
sub15 = c(3, "AA", "AB", "BB", "BB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"))

rownames(myd) <- c("cluster", paste("var", 1:12, sep=""))

Thus this data has 15 subjects sub1 : sub15 classified by categorical variables var1: var12. The cluster id is in the first row - with row name - cluster.

myd 
        sub1 sub2 sub3 sub4 sub5 sub6 sub7 sub8 sub9 sub10 sub11 sub12 sub13 sub14 sub15
cluster    1    1    1    1    1    1    2    2    2     2     2     2     3     3     3
var1      AB   AB   AB   AB   AB   AB   AA   AB   AA    AB    AA    AA    AB    AB    AA
var2      AB   BB   BB   BB   BB   BB   AA   AA   AA    AA    AA    AB    AB    BB    AB
var3      BB   BB   AB   AB   BB   BB   BB   AB   BB    BB    BB    BB    AB    BB    BB
var4      BB   BB   BB   BB   AB   BB   AB   AB   AB    AB    AB    BB    AB    AB    BB
var5      AA   AA   AA   AA   AB   AA   AA   AA   AA    AA    AB    AA    AB    AB    AA
var6      BB   BB   BB   BB   BB   AB   AB   AB   AB    BB    AB    AB    BB    BB    AB
var7      AB   AB   AB   AB   AB   AB   AB   AB   AB    AB    AB    AB    AB    AB    AB
var8      AA   AA   AA   AA   AA   AA   AB   AB   AB    AB    AB    AB    AA    AA    AB
var9      BB   BB   BB   BB   BB   BB   AB   AB   AB    AB    AB    AB    AB    AB    AB
var10     AB   AB   AB   AB   AB   AB   AB   AB   AB    AB    AB    AB    AA    AA    AB
var11     AA   AA   AA   AA   AA   AA   AB   AB   AB    AB    AB    AB    AB    AB    AB
var12     AB   AB   AB   AB   AB   AB   BB   BB   BB    BB    AB    BB    BB    BB    BB

I would like to see if the cluster is proper by calculating some of the measure (such as p-value) that can provide the probability that particular subject belong to certain cluster. How can I achieve this ? I do have a large number of variables / subjects, so I would need quicker solution as well.

$\endgroup$
4
  • $\begingroup$ How did you get the clusters? Are they a "real-world" label, something derived from a clustering algorithm, something in between? $\endgroup$
    – Danica
    Commented Jul 31, 2014 at 4:19
  • $\begingroup$ The cluster are not from statistical procedure (here from biological classification) - that is why we need to check them if that is correct. $\endgroup$
    – rdorlearn
    Commented Jul 31, 2014 at 4:29
  • $\begingroup$ check them if that is correct. But what is correct? Any classification is "correct" if it can be justified. To check a classification, as you request, you must clearly define the rules and the procedure of the classification. To do it on the data and see if there occured any discrepancy with the given classification. $\endgroup$
    – ttnphns
    Commented Aug 4, 2014 at 10:47
  • $\begingroup$ @ttnphns the rule is that the subs in same class are similar with each other compared that from other class. The classification here is natural/biological (for example chromosomes - markers from same chromosomes are correlated/associated in contrast to that from other chromosome are not significantly correlated or are independent). So I know the classification but how I got this classification is biological, but outcome should follow statistical rule - from the same group should be associated compared to other group. $\endgroup$
    – rdorlearn
    Commented Aug 4, 2014 at 11:38

1 Answer 1

2
+50
$\begingroup$

I am not sure if you are looking for something like this.

First you can calculate distance measure and use this distance measures in several ways - one of which of-course is hierarchical cluster analysis. You can calculated distance using daisy function in package cluster. The function uses “Gower's distance” (Gower , 1971 : Biometrics 27, 857–874) for non numerical data. Back to you data:

myd <- data.frame (
 sub1 = c(1, "AB", "AB", "BB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub2 = c(1, "AB", "BB", "BB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub3 = c(1, "AB", "BB", "AB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub4 = c(1, "AB", "BB", "AB", "BB", "AA", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub5 = c(1, "AB", "BB", "BB", "AB", "AB", "BB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub6 = c(1, "AB", "BB", "BB", "BB", "AA", "AB", "AB", "AA", "BB", "AB", "AA", "AB"),
sub7 = c(2, "AA", "AA", "BB", "AB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub8 = c(2, "AB", "AA", "AB", "AB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub9 = c(2, "AA", "AA", "BB", "AB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub10 = c(2, "AB", "AA", "BB", "AB", "AA", "BB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub11 = c(2, "AA", "AA", "BB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB"),
sub12 = c(2, "AA", "AB", "BB", "BB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"),
sub13 = c(3, "AB", "AB", "AB", "AB", "AB", "BB", "AB", "AA", "AB", "AA", "AB", "BB"),
sub14 = c(3, "AB", "BB", "BB", "AB", "AB", "BB", "AB", "AA", "AB", "AA", "AB", "BB"),
sub15 = c(3, "AA", "AB", "BB", "BB", "AA", "AB", "AB", "AB", "AB", "AB", "AB", "BB"))

rownames(myd) <- c("cluster", paste("var", 1:12, sep=""))

require(cluster)
myd1 <- data.frame (t(myd[-1,]))
d <- daisy(myd1)

Here the object d distance matrix, which can be used in several ways, one of which is clustering.

fit <- hclust(d, method="ward") 
plot(fit) # display dendogram

groups <- cutree(fit, k=3)
# draw dendogram with red borders around the 3 clusters 
rect.hclust(fit, k=3, border="red")

More attractive way to present the results is perhaps color coding creating phylogenic tree using package ape

require(ape)
colorCodes <- c("red", "green4", "blue")
class <- as.numeric (t(myd)[,1])
plot(as.phylo(fit), tip.color=colorCodes[class], type="fan")
plot(as.phylo(fit), tip.color=colorCodes[class], type="phylogram")

You can see here that sub15 is clearly miss-classified in class 2, should be in class 3. enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.