User Tools

Site Tools


en:class-eval_examples

Section: Numerical classification

Evaluation of classification results

Example 1: Project results onto ordination diagram of unconstrained ordination

library (vegan)
vltava.spe <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/vltava-spe.txt', row.names = 1)
dist_bc <- vegdist (log1p (vltava.spe), method = 'bray')
clus <- hclust (sqrt (dist_bc), method = 'ward.D2')
clus.cut <- cutree (clus, k = 5)
 
par (mfrow = c(1,2))
NMDS <- metaMDS (dist_bc)  # just to make sure it makes meaningful clusters
ordiplot (NMDS, type = 'n', main = 'NMDS ordination diagram (Bray-Curtis distances)')
points (NMDS, pch = 16, col = clus.cut)
plot (clus, cex = .5)
rect.hclust (clus, k = 5, border = 1:5)

Example 2: Using silhouette (library cluster)

Evaluates, if the sample has appropriate group membership. Samples with high s value are well clustered, s value around zero means that the sample is between two clusters, and negative s value means that the sample has been misclassified.

For example, we will use results of beta flexible numerical classification of vltava.spe data (see agnes (library cluster)):

## Example of silhouette function
 
## Following code is not necessary, if you already used examples above...
# library (cluster)
# dis <- vegdist (sqrt (vltava.spe), method = 'bray') # percentage cover data are transformed by square root
# cluster.flexible <- agnes (x = dis, method = 'flexible', par.method = 0.625)
# cluster.flexible.hclust <- as.hclust (cluster.flexible)
 
cl <- cutree (cluster.flexible.hclust, k = 5)
si <- silhouette (cl, dis)
plot (si)
 
# Group 3 has the highest number of misclassified samples, on the other hand, groups 1, 2 and 5 are well defined. 

Silhouette plot

# Comparison of silhouettes for single linkage, complete average linkage method.
# dis <- vegdist (sqrt (vltava.spe), method = 'bray') # percentage cover data are transformed by square root
# cluster.single <- hclust (d = dis, method = 'single')
# cluster.complete <- hclust (dis, 'complete')
# cluster.average <- hclust (dis, 'average')
 
par (mfrow = c(1,3))
plot (silhouette (cutree (cluster.single, k = 5), dis))
plot (silhouette (cutree (cluster.complete, k = 5), dis))
plot (silhouette (cutree (cluster.average, k = 5), dis))

Example 3: Fidelity of species to the cluster

library (indicspecies)  # to calculate fidelity
library (vegan)
vltava.spe <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/vltava-spe.txt', row.names = 1)
dist_bc <- vegdist (log1p (vltava.spe), method = 'bray')
clus <- hclust (sqrt (dist_bc), method = 'ward.D2')
clus.cut <- cutree (clus, k = 5)
 
tab <- multipatt (vltava.spe, cluster = clus.cut, fun = 'r.g')  # function 'r' is correlation coefficient (phi coef), g indicates that the groups are standardized per size
 
tab$sign[tab$sign$p.value<0.5,]  # this table indicates which species has significant fidelity to which cluster or combination of clusters (fidelity tested by Fisher's test); only significant (P<0.05) species are selected
          s.1 s.2 s.3 s.4 s.5 index      stat p.value
Abiealb23   0   0   0   0   1     5 0.5849757   0.005
Acerpla23   1   0   0   0   0     1 0.3985364   0.005
Acerpse23   0   0   0   1   0     4 0.2718779   0.100
Alnuglu23   0   1   0   0   0     2 0.6521616   0.005
Betupen23   0   0   1   0   1    14 0.3220558   0.035
Coryave23   0   1   0   0   1    12 0.3811221   0.010
Cratspe23   1   0   0   0   0     1 0.2121908   0.425
Euoneur23   0   1   0   0   0     2 0.3687661   0.010
Fagusyl23   0   0   0   1   0     4 0.3120710   0.045
Franaln23   0   0   1   0   0     3 0.3462817   0.040
Fraxexc23   0   1   0   0   0     2 0.2921876   0.050
Junicom23   0   0   1   0   0     3 0.2365250   0.140
Liguvul23   1   0   0   0   0     1 0.4561116   0.005
Lonixyl23   0   0   0   0   1     5 0.3563483   0.030
Piceabi23   0   1   0   0   0     2 0.2213071   0.330
Pinusyl23   0   0   1   0   0     3 0.5231362   0.005
Prunpad23   0   1   0   0   0     2 0.5161221   0.005
Prunspi23   1   0   0   0   0     1 0.2721655   0.125
Pyrupyr23   1   0   0   0   0     1 0.3844645   0.015
Querpet23   1   0   1   0   0     7 0.4093827   0.005
Querrob23   1   0   0   0   0     1 0.2526532   0.165
Reynjap23   0   1   0   0   0     2 0.3429972   0.070
Rhamcat23   1   0   0   0   0     1 0.3487968   0.015
Ribeuva23   1   0   0   0   0     1 0.2721655   0.150
Rosacan23   1   0   0   0   0     1 0.2990890   0.080
Rosapen23   0   1   0   0   0     2 0.2407717   0.480
Rosaspe23   1   0   0   0   0     1 0.2366064   0.110
Rubufru23   0   1   0   0   0     2 0.2740088   0.060
Salifra23   0   1   0   0   0     2 0.4527947   0.010
Salitri23   0   1   0   0   0     2 0.2407717   0.405
Salivim23   0   1   0   0   0     2 0.2407717   0.420
Sambnig23   0   0   0   0   1     5 0.4496048   0.005
Sorbauc23   0   1   1   0   1    23 0.2841786   0.080
Tilicor23   1   1   0   1   0    17 0.3308026   0.050
Tilipla23   1   1   0   1   0    17 0.1986532   0.385
Ulmugla23   0   1   0   0   0     2 0.3147620   0.070
Achimil1    1   0   0   0   0     1 0.3885143   0.020
Achitan1    1   0   0   0   0     1 0.5484085   0.005
Aconlyc1    0   0   0   0   1     5 0.2500000   0.270
Aconvar1    0   1   0   0   0     2 0.3980149   0.005
Actaspi1    0   0   0   0   1     5 0.4167222   0.010
Aegopod1    0   1   0   0   0     2 0.6972693   0.005
Aethcyn1    0   1   0   0   0     2 0.2151214   0.475
Agrocan1    0   1   0   0   0     2 0.2407717   0.420
Agrocap1    1   0   0   0   0     1 0.3219597   0.040
Agrosto1    0   1   0   0   0     2 0.2204466   0.340
...
...
...
summary (tab) # list of diagnostic species for each cluster (and combination of clusters if these clusters are merged)
Multilevel pattern analysis
---------------------------
  
  Association function: r.g
Significance level (alpha): 0.05

Total number of species: 274
Selected number of species: 127 
Number of species associated to 1 group: 107 
Number of species associated to 2 groups: 16 
Number of species associated to 3 groups: 4 
Number of species associated to 4 groups: 0 

List of species associated to each combination: 
  
  Group 1  #sps.  39 
stat p.value   
Euphcyp1  0.656   0.005 **
  Vinchir1  0.616   0.005 **
  Camprot1  0.610   0.005 **
  Hylomax1  0.599   0.005 **
  Poa.nem1  0.587   0.005 **
  Achitan1  0.548   0.005 **
  Bracpin1  0.544   0.005 **
  Anthram1  0.542   0.005 **
  Hypeper1  0.539   0.005 **
  Polyodo1  0.538   0.005 **
  Trifalp1  0.535   0.005 **
  Pimpsax1  0.527   0.005 **
  Diancar1  0.523   0.005 **
  Genitin1  0.521   0.005 **
  Allisen1  0.480   0.005 **
  Bromben1  0.480   0.010 **
  Liguvul23 0.456   0.005 **
  Silenut1  0.432   0.005 **
  Verocha1  0.399   0.010 **
  Acerpla23 0.399   0.005 **
  Geniger1  0.398   0.020 * 
  Achimil1  0.389   0.020 * 
  Knauarv1  0.389   0.020 * 
  Salvglu1  0.389   0.015 * 
  Poa.ang1  0.389   0.005 **
  Pyrupyr23 0.384   0.015 * 
  Secuvar1  0.381   0.020 * 
  Verbnig1  0.372   0.020 * 
  Carespe1  0.369   0.025 * 
  Galialb1  0.369   0.010 **
  Festrub1  0.368   0.020 * 
  Hedehel1  0.365   0.025 * 
  Rhamcat23 0.349   0.015 * 
  Verooff1  0.341   0.030 * 
  Agrocap1  0.322   0.040 * 
  Hierpil1  0.319   0.040 * 
  Festhet1  0.311   0.010 **
  Fallcon1  0.304   0.045 * 
  Caremur1  0.289   0.020 * 
  
  Group 2  #sps.  44 
stat p.value   
Lycoeur1  0.961   0.005 **
  Phalaru1  0.868   0.005 **
  Festgig1  0.861   0.005 **
  Sympoff1  0.768   0.005 **
  Stacsyl1  0.722   0.005 **
  Calysep1  0.721   0.005 **
  Myospal1  0.714   0.005 **
  Aegopod1  0.697   0.005 **
  Ranurep1  0.675   0.005 **
  Alnuglu23 0.652   0.005 **
  Stelnem1  0.629   0.005 **
  Lysivul1  0.622   0.005 **
  Cirsole1  0.596   0.005 **
  Angesyl1  0.576   0.005 **
  Valeexc1  0.563   0.005 **
  Rumeaqu1  0.552   0.005 **
  Mentx.v1  0.544   0.005 **
  Galiapa1  0.543   0.005 **
  Scronod1  0.521   0.005 **
  Prunpad23 0.516   0.005 **
  Bidefro1  0.509   0.005 **
  Soladul1  0.497   0.005 **
  Cardper1  0.482   0.005 **
  Lythsal1  0.479   0.005 **
  Chaehir1  0.477   0.005 **
  Artevul1  0.466   0.005 **
  Impagla1  0.465   0.005 **
  Salifra23 0.453   0.010 **
  Myosaqu1  0.441   0.005 **
  Urtidio1  0.431   0.005 **
  Mentlon1  0.416   0.015 * 
  Carebri1  0.408   0.005 **
  Poa.pal1  0.407   0.005 **
  Aconvar1  0.398   0.005 **
  Cusceur1  0.398   0.015 * 
  Humulup1  0.382   0.005 **
  Euoneur23 0.369   0.010 **
  Gleched1  0.353   0.025 * 
  Cardama1  0.343   0.040 * 
  Silespe1  0.343   0.040 * 
  Elymcan1  0.342   0.025 * 
  Carebue1  0.336   0.035 * 
  Glycmax1  0.324   0.010 **
  Fraxexc23 0.292   0.050 * 
  
  Group 3  #sps.  6 
stat p.value   
Avenfle1  0.686   0.005 **
  Pinusyl23 0.523   0.005 **
  Vaccmyr1  0.492   0.005 **
  Senevis1  0.393   0.010 **
  Hiermur1  0.388   0.020 * 
  Franaln23 0.346   0.040 * 
  
  Group 4  #sps.  2 
stat p.value   
Chelmaj1  0.480   0.005 **
  Fagusyl23 0.312   0.045 * 
  
  Group 5  #sps.  16 
stat p.value   
Lunared1  0.752   0.005 **
  Seneova1  0.715   0.005 **
  Cardimp1  0.711   0.005 **
  Prenpur1  0.649   0.005 **
  Oxalace1  0.644   0.005 **
  Mercper1  0.640   0.005 **
  Abiealb23 0.585   0.005 **
  Impanol1  0.458   0.010 **
  Athyfil1  0.453   0.005 **
  Sambnig23 0.450   0.005 **
  Actaspi1  0.417   0.010 **
  Milieff1  0.408   0.005 **
  Galemon1  0.405   0.015 * 
  Galiodo1  0.367   0.015 * 
  Lonixyl23 0.356   0.030 * 
  Cardfle1  0.338   0.045 * 
  
  Group 1+2  #sps.  2 
stat p.value   
Stelhol1 0.505   0.005 **
  Lamimac1 0.358   0.020 * 
  
  Group 1+3  #sps.  6 
stat p.value   
Hiersab1  0.547   0.005 **
  Lychvis1  0.482   0.005 **
  Hierlac1  0.446   0.005 **
  Querpet23 0.409   0.005 **
  Cytinig1  0.373   0.015 * 
  Festpal1  0.355   0.010 **
  
  Group 1+4  #sps.  1 
stat p.value  
Clinvul1 0.374   0.015 *
  
  Group 2+4  #sps.  1 
stat p.value  
Galespc1 0.358   0.015 *
  
  Group 2+5  #sps.  1 
stat p.value   
Coryave23 0.381    0.01 **
  
  Group 3+4  #sps.  1 
stat p.value   
Luzuluz1 0.484   0.005 **
  
  Group 3+5  #sps.  1 
stat p.value  
Betupen23 0.322   0.035 *
  
  Group 4+5  #sps.  3 
stat p.value   
Dryofil1 0.410   0.005 **
  Moehtri1 0.410   0.015 * 
  Dryocar1 0.342   0.035 * 
  
  Group 1+2+4  #sps.  1 
stat p.value  
Tilicor23 0.331    0.05 *
  
  Group 2+4+5  #sps.  3 
stat p.value   
Asareur1 0.520   0.005 **
  Dryodil1 0.469   0.005 **
  Melinut1 0.350   0.025 * 
  ---
  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
en/class-eval_examples.txt · Last modified: 2020/05/14 08:57 by David Zelený