User Tools

Site Tools


en:pcoa_nmds_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:pcoa_nmds_examples [2019/01/21 01:00]
David Zelený created
en:pcoa_nmds_examples [2019/02/26 23:33] (current)
David Zelený
Line 1: Line 1:
-====== Unconstrained ​ordination ​====== +Section: [[en:ordination]] 
-===== Principal Coordinate Analysis ​(PCoA) =====+===== PCoA & NMDS (distance-based unconstrained ordination) ===== 
 [[{|width: 7em; background-color:​ white; color: navy}pcoa_nmds|Theory]] [[{|width: 7em; background-color:​ white; color: navy}pcoa_nmds|Theory]]
 [[{|width: 7em; background-color:​ white; color: navy}pcoa_nmds_R|R functions]] [[{|width: 7em; background-color:​ white; color: navy}pcoa_nmds_R|R functions]]
Line 40: Line 41:
 Note that ''​names''​ argument adds the names to tickmarks on horizontal axis, ''​las''​ argument influences rotation of labels on both x and y axis (see ''?​par''​ for explanation) and ''​ylab''​ adds the label to the vertical axis. Note that ''​names''​ argument adds the names to tickmarks on horizontal axis, ''​las''​ argument influences rotation of labels on both x and y axis (see ''?​par''​ for explanation) and ''​ylab''​ adds the label to the vertical axis.
 {{ :​obrazky:​eurodist_cities_pcoa_screeplot.png|}} {{ :​obrazky:​eurodist_cities_pcoa_screeplot.png|}}
 +
 +==== Example 2: NMDS on the Morse code confusion matrix ====
 +
 +Use data about confusion of different Morse codes, originating from [[en:​data:​morse|Rothkopf'​s experiment with Morse codes]]. This is a classical data set, used by Shepard (1962)((Shepard,​ R. N. (1962): The Analysis of Proximities:​ Multidimensional Scaling with an Unknown Distance Function, I and II. //​Psychometrika//,​ 27: 125-139 and 219-246.)) to demonstrate the use of NMDS analysis.
 +
 +<code rsplus>
 +library (vegan)
 +morse.dist <- read.delim ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​morsecodes-dist.txt',​ row.names = 1, head = T)
 +names (morse.dist) <- rownames (morse.dist)
 +NMDS <- metaMDS (morse.dist)
 +NMDS
 +</​code>​
 +The stress values are in the following output:
 +<​code>​
 +Call:
 +metaMDS(comm = morse.dist) ​
 +
 +global Multidimensional Scaling using monoMDS
 +
 +Data:     ​morse.dist ​
 +Distance: user supplied ​
 +
 +Dimensions: 2 
 +Stress: ​    ​0.1800255 ​
 +Stress type 1, weak ties
 +Two convergent solutions found after 1 tries
 +Scaling: centring, PC rotation ​
 +Species: scores missing
 +</​code>​
 +
 +The ordination diagram and Shepard diagram could be drawn in the following way:
 +<code rsplus>
 +par (mfrow = c(1,2))
 +ordiplot (NMDS, cex = 1.5, type = '​t'​)
 +stressplot (NMDS)
 +</​code>​
 +{{:​obrazky:​rothkopfs_morse_nmds.png|}}
 +From left to right there is a gradient of increasing code length, from bottom up increases the proportion of long beeps within the code.
 +
 +==== Example 3: NMDS of river valley dataset ====
 +
 +<code rsplus>
 +vltava.spe <- read.delim ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​vltava-spe.txt',​ row.names = 1)
 +NMDS <- metaMDS (vltava.spe)
 +</​code>​
 +<​code>​
 +Square root transformation
 +Wisconsin double standardization
 +Run 0 stress 0.2022791 ​
 +Run 1 stress 0.2193042 ​
 +Run 2 stress 0.2130607 ​
 +Run 3 stress 0.208742 ​
 +Run 4 stress 0.2022791 ​
 +... procrustes: rmse 9.278716e-06 ​ max resid 3.31574e-05 ​
 +*** Solution reached
 +</​code>​
 +<​code>​
 +NMDS
 +</​code>​
 +<​code>​
 +Call:
 +metaMDS(comm = vltava.spe) ​
 +
 +global Multidimensional Scaling using monoMDS
 +
 +Data:     ​wisconsin(sqrt(vltava.spe)) ​
 +Distance: bray 
 +
 +Dimensions: 2 
 +Stress: ​    ​0.2022791 ​
 +Stress type 1, weak ties
 +Two convergent solutions found after 4 tries
 +Scaling: centring, PC rotation, halfchange scaling ​
 +Species: expanded scores based on ‘wisconsin(sqrt(vltava.spe))’ ​
 +</​code>​
 +
 +If the default setting of metaMDS function is used, the data are automatically (if necessary) transformed (in this case, combination of wisconsin and sqrt transformation was used). In this case, stress value is 20.2.
 +
 +To draw the result, use the function ''​ordiplot''​. In this case, using ''​type = '​t'''​ will add text labels (default setting adds only points):
 +<code rsplus>
 +ordiplot (NMDS, type = '​t'​)
 +</​code>​
 +{{:​obrazky:​ordination_unc21.png?​600|}}
 +<code rsplus>
 +par (mfrow = c(1,2)) # this function divides plotting window into two columns
 +stressplot (NMDS)
 +plot (NMDS, display = '​sites',​ type = '​t',​ main = '​Goodness of fit') # this function draws NMDS ordination diagram with sites
 +points (NMDS, display = '​sites',​ cex = goodness (NMDS)*200) # and this adds the points with size reflecting goodness of fit (bigger = worse fit)
 +</​code>​
 +{{:​obrazky:​ordination_unc20.png?​900|}}
 +
 +
  
en/pcoa_nmds_examples.1548003630.txt.gz · Last modified: 2019/01/21 01:00 by David Zelený