Valid XHTML     Valid CSS2    

Exemple de CAH (classification ascendante hiérarchique) avec R

1. Code R

Fichier xmp2.r :


     # # (gH)   -_-  xmp2.r  ;  TimeStamp (unix) : 09 Novembre 2017 vers 14:10
     
     library(vegan)  # pour vegdist()
     library(ape)    # pour as.phylo() et plot.phylo()
     
     # lecture des données
     
     xmp2 <- as.matrix(read.table("xmp2.data",header=FALSE,row.names=1))
     print(xmp2)
     
     # calcul de la matrice des distances
     
     mdc <- vegdist(x=xmp2,method="jaccard")
     print(mdc)
     
     # classification hiérarchique
     
     cah <- hclust(mdc,method="average")
     print(cah)
     desc <- data.frame(cbind(round(cah$height,3),cah$merge))
     names(desc) <- c("Niveau","Aine","Benjamin")
     print(desc)
     
     # tracé via plot.hclust et plot.phylo
     
     plot(cah, hang=-1,main="Dendrogramme 1")
     plot.phylo(as.phylo(cah), direction="leftwards",main="Dendrogramme 2",label.offset=0.01)
     
     

2. Résultats


            V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51
     SA4380  1  1  1  0  0  1  1  0   1   0   1   0   0   0   1   0   0   0   0   0   0   1   1   1   1   1   1   1   1   1   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
     SA4276  1  1  1  0  0  1  1  0   1   1   0   1   0   0   0   0   0   0   0   0   0   1   1   1   1   1   1   0   0   0   0   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
     SA4280  1  1  1  0  0  1  1  0   1   0   0   0   1   0   0   1   0   0   0   0   0   1   1   1   1   1   1   0   0   0   0   1   0   0   0   0   1   1   1   1   0   0   0   0   0   0   0   0   0   0
     SA4282  1  1  1  0  0  1  1  0   1   1   0   0   0   1   0   0   0   0   0   0   0   1   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   1   1   0   0   0   0   0   0
     SB4274  0  1  1  0  0  1  1  0   1   1   0   0   0   0   0   0   0   0   0   0   0   1   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   1   1   0   0
     SC4277  1  1  0  0  1  1  1  1   0   1   0   0   0   0   1   1   0   0   0   0   0   1   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   1   1   1
     SC4381  1  1  0  0  1  1  1  1   0   1   0   0   0   0   0   0   1   1   0   0   0   1   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   1   0   0
     SC4378  1  1  0  0  1  1  1  1   0   1   0   0   0   0   0   0   0   0   1   0   0   1   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
     SD4281  1  1  0  0  1  1  1  0   1   1   0   0   0   0   0   0   0   0   1   1   0   1   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   1   0
     SD4283  1  1  0  0  1  1  1  0   1   1   0   0   0   0   0   0   0   0   0   1   0   1   1   1   1   1   1   0   0   0   1   0   0   0   0   0   0   1   0   0   0   0   0   0   1   0   0   0   0   1
     ZZ4283  0  0  0  1  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
     
               SA4380    SA4276    SA4280    SA4282    SB4274    SC4277    SC4381    SC4378    SD4281    SD4283
     SA4276 0.4800000
     SA4280 0.5384615 0.4800000
     SA4282 0.5384615 0.4800000 0.4800000
     SB4274 0.5600000 0.5000000 0.5600000 0.4347826
     SC4277 0.5925926 0.5925926 0.5925926 0.5925926 0.5000000
     SC4381 0.6428571 0.5925926 0.6428571 0.5925926 0.3636364 0.3478261
     SC4378 0.5652174 0.5000000 0.5652174 0.5000000 0.5238095 0.3500000 0.3500000
     SD4281 0.5600000 0.5000000 0.5000000 0.5000000 0.5217391 0.4347826 0.5000000 0.2777778
     SD4283 0.5200000 0.5200000 0.5200000 0.5200000 0.4782609 0.3913043 0.4583333 0.4000000 0.3333333
     ZZ4283 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
     
     Call:
     hclust(d = mdc, method = "average")
     
     Cluster method   : average
     Distance         : jaccard
     Number of objects: 11
     
        Niveau Aine Benjamin
     1   0.278   -8       -9
     2   0.348   -6       -7
     3   0.367  -10        1
     4   0.414    2        3
     5   0.435   -4       -5
     6   0.480   -1       -2
     7   0.509   -3        6
     8   0.509    4        5
     9   0.549    7        8
     10  1.000  -11        9
     

       non su

       non su

3. Données

Fichier xmp2.data :


     SA4380        1    1    1    0    0    1    1    0    1    0    1    0    0    0    1    0    0    0    0    0    0    1    1    1    1    1    1    1    1    1    1    0    0    0    0    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
     SA4276        1    1    1    0    0    1    1    0    1    1    0    1    0    0    0    0    0    0    0    0    0    1    1    1    1    1    1    0    0    0    0    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
     SA4280        1    1    1    0    0    1    1    0    1    0    0    0    1    0    0    1    0    0    0    0    0    1    1    1    1    1    1    0    0    0    0    1    0    0    0    0    1    1    1    1    0    0    0    0    0    0    0    0    0    0
     SA4282        1    1    1    0    0    1    1    0    1    1    0    0    0    1    0    0    0    0    0    0    0    1    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    0    1    1    1    1    1    0    0    0    0    0    0
     SB4274        0    1    1    0    0    1    1    0    1    1    0    0    0    0    0    0    0    0    0    0    0    1    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    1    1    1    1    1    0    0
     SC4277        1    1    0    0    1    1    1    1    0    1    0    0    0    0    1    1    0    0    0    0    0    1    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    1    0    0    1    1    1
     SC4381        1    1    0    0    1    1    1    1    0    1    0    0    0    0    0    0    1    1    0    0    0    1    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    1    1    1    1    0    0
     SC4378        1    1    0    0    1    1    1    1    0    1    0    0    0    0    0    0    0    0    1    0    0    1    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
     SD4281        1    1    0    0    1    1    1    0    1    1    0    0    0    0    0    0    0    0    1    1    0    1    1    1    1    1    1    0    0    0    0    0    0    0    0    0    0    0    1    0    0    0    0    0    0    0    0    0    1    0
     SD4283        1    1    0    0    1    1    1    0    1    1    0    0    0    0    0    0    0    0    0    1    0    1    1    1    1    1    1    0    0    0    1    0    0    0    0    0    0    1    0    0    0    0    0    0    1    0    0    0    0    1
     ZZ4283        0    0    0    1    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
     

 

 

retour gH    Retour à la page principale de   (gH)