Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Multivariate Analysis Biology 4605/7220 Chih-Lin Wei Canadian Health Oceans Network Postdoc Fellow Ocean Science Centre, MUN.

Similar presentations

Presentation on theme: "Introduction to Multivariate Analysis Biology 4605/7220 Chih-Lin Wei Canadian Health Oceans Network Postdoc Fellow Ocean Science Centre, MUN."— Presentation transcript:

1 Introduction to Multivariate Analysis Biology 4605/7220 Chih-Lin Wei Canadian Health Oceans Network Postdoc Fellow Ocean Science Centre, MUN

2 My Background Benthic ecologist: Community ecology How environments control macroecological patterns in the deep-sea Interested in R but “NOT a statistician”. Education: BS in Zoology in Taiwan; MS & PhD in Biological Oceanography, Texas A&M University Current project: Scale-up regional benthic diversity and standing stock pattern using ecological modeling approaches

3 Lecture Contents Visualization Resemblance index Cluster analysis Ordination Correlation Testing for difference Other stuff Clarke & Warwick (2001)

4 Front Matter Mostly non-parametric, permutation-based techniques Start with graphical concept Followed by examples in simple R codes No more than 3 lines of code for each example Most functions in base R or package “vegan” All analyses are available on commercial software (PRIMER-E) [demo version]demo version

5 R packages # Install and load R Packages install.packages( c("vegan", "scatterplot3d", "reshape2", "lattice", "clustsig") ) library( vegan ) library( scatterplot3d ) library( reshape2 ) library( lattice ) library( clustsig)

6 First thing first, plot the data # Violent Crime Rates by US State USArrests plot( USArrests[,1:2] )

7 3D Scatter Plot scatterplot3d( USArrests[,1:3] )

8 Scatterplot Matrices pairs( USArrests )

9 Lattice Graphs # Melt dataframe to flat format m = melt( USArrests, id.vars = "Assault" ) m # Multipanel scatter plot xyplot( value ~ Assault | variable, data = m )

10 Resemblance/distance Indices Clarke & Warwick (2001) *Not good for data with lots of zero (e.g. species abundance)

11 Resemblance/distance Indices D = 0, if species are identical in 2 samples D = 1, if 2 samples have no species in common Better for species abundance data (with lots of zero)

12 Resemblance/distance Indices # Euclidean Distance: dist( USArrests ) # Bray-Crutis Dissimilarity # Vegetation in lichen pastures data( varespec ) varespec vegdist( varespec )

13 Hierarchical Clustering Patterns in distance or dissimilarity matrix is difficult to detect. Find natural grouping by successive fusing of samples

14 Hierarchical Clustering Linkage Options: Single linkage (neareast neighbour clustering) Complete linkage (furthest neighbour clustering) Group-average linkage Ward’s minimum variance Group 1 Group 2 Sp 1 Sp 2 Single Link Complete Link

15 Hierarchical Clustering # Normalization arrest = scale( USArrests, center = FALSE ) # Euclidean Distance d = dist( arrest ) # Dendrograms plot( hclust( d, "single" ) ) plot( hclust( d, "complete" ) ) plot( hclust( d, "average" ) ) plot( hclust( d, "ward" ) )

16 Determine Numbers of Clusters # Using Ward's mehtod clus = hclust( d, "ward" ) plot( clus ) # Cut into 3 groups rect.hclust( clus, k = 3 ) K = 3 K = 6

17 Determine Significant Clusters Clarke et al. (2008, JEMBE 366:56-69)

18 Similarity Profile Test # 999 permutation # Group-average clustering # alpha = 0.05 clus2 = simprof( arrest ) simprof.plot( clus2 ) * Colors = significant clusters

19 Motivations for Ordination Dendrogram is still difficult to understand Clustering forced samples into groups despites the compositional changes may be continuous. Ordination reduces dimensionality of multivariate data (data cloud so to speak) Preferably, capture majority of the information as bivariate data frame, so the multivariate patterns can be shown on a scatter plot.

20 Principal Component Analysis (PCA) Clarke & Warwick (2001) 2 species example

21 Principal Component Analysis (PCA) PC1 maximizes variance of points projected on it. PC2 is perpendicular to PC1 PC3 is perpendicular to PC1 and PC2 New orthogonal axes are linear combination of old data: PC1 = 0.62 Sp Sp Sp3 PC2 = Sp Sp Sp3 PC3 = 0.28 Sp Sp Sp3 Clarke & Warwick (2001) 3 species example

22 Principal Component Analysis (PCA) # PCA pca = princomp( arrest ) # New orthogonal axes pairs( pca$scores )

23 Principal Component Analysis (PCA) # Variable contributions # PC1 = Murder -0.6 Assault Rape pca$loading # Variance of PC axes plot( pca ) # Total variance explained summary( pca )

24 Principal Component Analysis (PCA) #Cut dentrogram for 6 cluster group = cutree( clus, 6 ) plot( pca$scores, type = "n" ) text( pca$scores, names( group ), col = group )

25 Principal Component Analysis (PCA) # Add variable contributions biplot( pca, scale = 0 )

26 Non-Metric Multidimensional Scaling (nMDS) Ordination bases on ranked resemblance (or distance) matrix Robust and flexible for all kind of resemblance indices Using iterative procedure, successively refine the locations of ordination points according to the ranked dissimilarities of samples Better choice for species abundance data (comparing to PCA)

27 Multidimensional Scaling (nMDS) mds = metaMDS( arrest ) stressplot( mds )

28 Multidimensional Scaling (nMDS) # Ordination with 6 clusters plot( mds$points, type = "n" ) text( mds$points, names( group ), pch = group, col = group) # Add variable score # Weighted average biplot( mds$points, mds$species )

29 Correlation between Matrices # Vegetation and environment # in lichen pastures data( varespec ) data( varechem ) # Bray-Crutis Dissimilarity veg.dist = vegdist( varespec ) # Euclidean distance env.dist = dist( scale( varechem ) )

30 Mantel Test ρ Correlation Sites Species Sites 1, 2, 3,…….... BC Rank Environ. Sites 1, 2, 3,…….... ED Rank

31 r = 0.3 # Mantel test # Based on 999 permutations # Pearson's correlation man = mantel( veg.dist, env.dist ) man # Distribution of permuted r hist ( man$perm ) Mantel Test

32 Best Environmental Subsets ρ Correlation Sites Species Sites 1, 2, 3,…….... BC Rank Environ. Sites 1, 2, 3,…….... ED Rank

33 BIOENV bioenv( varespec, varechem ) # possible subsets # Subset of environmental variables with best correlation to community data

34 Testing Group Difference for Community Data data( dune ) #Vegetation in Dutch Dune Meadows dune # More species (variables) than samples # Dominance of zero values # Violates multivariate normality and constant variance across the groups # A robust, permuatation-based test is needed for community data.

35 Analysis of Similarity (ANOSIM) R = 1: Within group are more similar than between groups R = 0: Between and within group are the same in average R is an absolute measure of group seperation Sites Species Sites 1, 2, 3,…….... BC Rank r B = Avg. rank between groups r W = Avg. rank within groups n = sample size

36 Analysis of Similarity (ANOSIM) # Environment factors in Dutch Dune Meadows data( dune.env ) # Does moisture has effect on vegetation? Moisture = as.numeric( dune.env$Moisture ) # Run a MDS on dune vegetation mds = metaMDS( dune ) # MDS plot seems to suggest moisture effect plot( mds$points, pch = 21, bg = Moisture, cex = Moisture )

37 Analysis of Similarity (ANOSIM) aos = anosim( dune, Moisture ) aos # Distribution of permuted R hist( aos$perm ) R = 0.43

38 Other Useful Functions Clustering: pam() for clustering around medoids and clara() for clustering large data (both in “cluster”) pvclust() in “pvclust” for assessing the uncertainty in hierarchical cluster analysis Ordination: Great PCA video explanation on YOUTUBEYOUTUBE imputePCA() in “missMDA” for handling missing data cca() and rda() in “vegan” for constrained type of ordinations Testing difference: mrpp() in “vegan” for ANOSIM type analysis but using original dissimilarities instead of their ranks. adonis() in “vegan” for robust and flexible multivariate permutational analysis of variance (e.g. factorial & nested design, mixed model, etc.) betadisper() in “vegan” for testing constant multivariate variance (or dispersion)

Download ppt "Introduction to Multivariate Analysis Biology 4605/7220 Chih-Lin Wei Canadian Health Oceans Network Postdoc Fellow Ocean Science Centre, MUN."

Similar presentations

Ads by Google