##### To generate Mantel correlations between genetic distance and geographic distance, first install the ecodist package into R: require(ecodist) ##### Next, you will need to enter geographic distances into R. ##### We have distance matrices in the files drain.csv and linear.csv. ##### Import each of these into data frames called drain and linear (What do these look like?): drainage<-read.csv("drainage.csv") linear<-read.csv("linear.csv") ###### Convert the data frames into matrices, dropping the first row and column: drainage.mat<-as.matrix(drainage[2:13,2:13]) linear.mat<-as.matrix(linear[2:13,2:13]) ###### The following command will extract the lower triangle below the diagonal of the matrix, ###### you will need this for the mantel test below: drainage.mat[lower.tri(drainage.mat)] ##### Genetic distance matrix from STRUCTURE (brought into Excel, converted to CSV, diagonal made NA. genetic<-read.csv("genetic.csv") genetic.mat<-as.matrix(genetic[2:13,2:13]) ##### Use the function mantel to calculate your Mantel correlations: mantel(genetic.mat[lower.tri(genetic.mat)]~linear.mat[lower.tri(linear.mat)],nperm=100) mantel(genetic.mat[lower.tri(genetic.mat)]~drain.mat[lower.tri(drain.mat)],nperm=100) ##### Why did we go through all this trouble rather than just running a Pearson's correlation? cor(genetic.mat[lower.tri(genetic.mat)],linear.mat[lower.tri(linear.mat)]) cor(genetic.mat[lower.tri(genetic.mat)],drainage.mat[lower.tri(drainage.mat)])