The Asymetric-eigenvector-maps (AEMs)

Asymetric Eigenvector Maps (AEM) were developed by Blanchet, Legendre and Borcard (2008 to model multivariate spatial distributions generated by an asymetric directional process, such as current direction.

In a seascape genomics study, AEM variables are generated by translating the presence of a connection - i.e., dispersal probability from the biophysical model >0 between all pairs of sites into a site-by-edge matrix.

The information needed to construct such AEM variables is: 1) a connectivity matrix linking the sites to one another and giving information about the direction of the hypothesized asymmetric process influencing the response variable(s) 2) the spatial coordinates of your sampling sites

The connectivity matrix results from the biophysical model of larval dispersal that estimates the probability of connectivity due to oceanographic circulation.

Optionnally, weights attached to the edges (links) can be added to the analysis resulting. So two types of AEM vectors can be built : 1) AEM variables weighted 2) AEM variables non-weighted

For both AEMs and dbMEMs, the larger eigenvectors model broad-scale spatial structures, whereas the smaller eigenvectors model fine-scale spatial structures Dray et al., 2012.

We will then evaluate the effect of directional currents on spatial patterns of neutral genetic variation using the derived AEM predictor variables implemented in a redundancy analysis (RDA) framework.

“The development of AEM has provided a new and more powerful way for studying ocean current influence of genomic variation. It has also significantly enhanced the proportion of variation explained by ocean current.” see Liggings et al..

Download libraries

library(reshape2)
library(ggplot2)
library(adespatial)
## Registered S3 methods overwritten by 'adegraphics':
##   method         from
##   biplot.dudi    ade4
##   kplot.foucart  ade4
##   kplot.mcoa     ade4
##   kplot.mfa      ade4
##   kplot.pta      ade4
##   kplot.sepan    ade4
##   kplot.statis   ade4
##   scatter.coa    ade4
##   scatter.dudi   ade4
##   scatter.nipals ade4
##   scatter.pco    ade4
##   score.acm      ade4
##   score.mix      ade4
##   score.pca      ade4
##   screeplot.dudi ade4
## Registered S3 method overwritten by 'spdep':
##   method   from
##   plot.mst ape
## Registered S3 methods overwritten by 'adespatial':
##   method             from       
##   plot.multispati    adegraphics
##   print.multispati   ade4       
##   summary.multispati ade4
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Import the connectivity matrix and the spatial coordinates

AEM eigenfunctions can be constructed from a ocean current network and the ecological example presented in the paper of Xuereb et al. perfectly illustrate the use of AEM, starting from a set of 20 sampling sites in a single oceanographic network, located in the Western part of the Canadian coast.

A caption

A caption

Transform connectivity matrix into a matrix.

con_mat <- as.matrix(con_mat)

Check the dimension of the connectivity matrix.

dim(con_mat)
## [1] 20 20

Visualize the connectivity matrix.

First, change your matrix from wide to long format and rename the columns.

melted_con <- melt(con_mat)
colnames(melted_con) <- c("SITE1","SITE2","Dispersal")

Create the graph of the connectivity matrix and observe the amount of 0 values.

ggplot(data = melted_con, aes(SITE1, SITE2, fill = Dispersal))+
  geom_tile(color = "black")+
  scale_fill_gradient2(low = "white", mid ="white", high = "brown2", space = "Lab", 
                       name="Dispersal probabilities") +
  ylab("Sampling location A")+
  xlab("Sampling location B")+
  theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 8, hjust = 1))+ 
  theme(legend.position="top",legend.text = element_text(color = "black", size = 6)) +
  coord_fixed()

Separate the connectivity matrix in the upper and lower parts.

upper <- con_mat[upper.tri(con_mat, diag = TRUE)]
lower <- con_mat[lower.tri(con_mat, diag = TRUE)]

When connectivity between a given pair of sites was > 0 in both directions, we want to select the direction with the highest probability of dispersal.

Find the highest probability between two sites by examining the upper and lower parts of the connectivity matrix.

highest <- vector()
for (i in 1 : length(upper)) {
  if (upper[i] < lower[i]) {
    highest[i] <- lower[i]
  } else {
    highest[i] <- upper[i]
  }
}

Then, we replace the uppper matrix of the object con_mat with the highest values.

con_mat2 <- con_mat
con_mat2[upper.tri(con_mat2, diag = TRUE)] <- highest

We also replace the lower matrix by 0 as we want to only keep the upper part of the connectivity matrix that contains the highest probabilities.

con_mat2[lower.tri(con_mat2, diag = T)] <- 0
diag(con_mat2) <- diag(con_mat)
dim(con_mat2)
## [1] 20 20

Use the geographic coordinates information of your sampling site

Import geographic coordinates of your study and exclude the four sampling sites in Alaska.

sites <- read.table("24_sites.txt", header=TRUE)
sites <- sites[-c(21:24), ]
sites
##    Year     Month               Site Abb      Lat      Long Site_nb Lat_round
## 1  2015    August         OgdenPoint OGD 48.40822 -123.3875       1    48.408
## 2  2015    August SouthernGulfIsland SGI 48.75678 -123.3799       2    48.757
## 3  2015    August           Lasqueti LAS 49.47478 -124.1826       3    49.475
## 4  2015 September        JervisInlet JER 49.75303 -124.0011       4    49.753
## 5  2014      July             Tofino TOF 49.24820 -125.9384       5    49.248
## 6  2014    August     CracroftIsland CRA 50.52120 -126.5646       6    50.521
## 7  2015    August            RockBay RBY 50.33027 -125.4666       7    50.330
## 8  2015    August      ShewellIsland SHE 50.65893 -126.2377       8    50.659
## 9  2015      July      MalcolmIsland MAL 50.62737 -127.1282       9    50.627
## 10 2015      June           Quatsino QUA 50.49977 -127.8717      10    50.500
## 11 2015      June         HopeIsland HOP 50.89923 -127.8512      11    50.899
## 12 2015      July        TableIsland TBL 51.27213 -127.8038      12    51.272
## 13 2014      July      CalvertIsland CAL 51.69000 -128.1425      13    51.690
## 14 2014   October             Tolmie TOL 52.71327 -128.5782      14    52.713
## 15 2014   October       PrinceRupert PRI 54.19700 -130.3660      15    54.197
## 16 2014   October             Legace LEG 54.68200 -130.4640      16    54.682
## 17 2014    August          JuanPerez JUA 52.63200 -131.3960      17    52.632
## 18 2014    August             Selwyn SEL 52.93882 -131.9049      18    52.939
## 19 2014      July       RennellSound REN 53.39900 -132.6600      19    53.399
## 20 2014      July          Mazarredo MAZ 54.10000 -132.5531      20    54.100
##    Long_round
## 1    -123.387
## 2    -123.380
## 3    -124.183
## 4    -124.001
## 5    -125.938
## 6    -126.565
## 7    -125.467
## 8    -126.238
## 9    -127.128
## 10   -127.872
## 11   -127.851
## 12   -127.804
## 13   -128.143
## 14   -128.578
## 15   -130.366
## 16   -130.464
## 17   -131.396
## 18   -131.905
## 19   -132.660
## 20   -132.553

Select the geographic coordinates (Latitude and Longitude) from the sitesobject.

xy <- sites[,4:6]

Give an unique number to each site, here there are 20 sites so we have the sequence of numbers between 1 and 20.

xy$Nb <- seq(1, 20, 1)

Change the order of the columns by ensuring Longitude is before Latitude. And check the final output.

xy <- xy[,c(4,3,2)]   
xy
##    Nb      Long      Lat
## 1   1 -123.3875 48.40822
## 2   2 -123.3799 48.75678
## 3   3 -124.1826 49.47478
## 4   4 -124.0011 49.75303
## 5   5 -125.9384 49.24820
## 6   6 -126.5646 50.52120
## 7   7 -125.4666 50.33027
## 8   8 -126.2377 50.65893
## 9   9 -127.1282 50.62737
## 10 10 -127.8717 50.49977
## 11 11 -127.8512 50.89923
## 12 12 -127.8038 51.27213
## 13 13 -128.1425 51.69000
## 14 14 -128.5782 52.71327
## 15 15 -130.3660 54.19700
## 16 16 -130.4640 54.68200
## 17 17 -131.3960 52.63200
## 18 18 -131.9049 52.93882
## 19 19 -132.6600 53.39900
## 20 20 -132.5531 54.10000

Create the site-by-edges matrix E

To quantify the connexions (edges) - using the vocabulary of graph theory - between the sites and construct site-by-edges matrix E, sites (rows of table E) and edges (columns) are numbered; alternatively, they can be given names. Keep number associated to each site in the highest probabilities matrix.

edges.highest.prob <- con.mat.highest.prob.no0[,c(2,3)]
edges <- edges.highest.prob
edges
##     SITE1 SITE2
## 1       1     1
## 2       2     1
## 3       2     2
## 4       3     1
## 5       3     2
## 6       3     3
## 7       4     1
## 8       4     2
## 9       4     3
## 10      4     4
## 11      5     1
## 12      5     2
## 13      5     3
## 14      5     4
## 15      5     5
## 16      6     1
## 17      6     2
## 18      6     3
## 19      6     6
## 20      7     1
## 21      7     2
## 22      7     3
## 23      7     4
## 24      7     6
## 25      7     7
## 26      8     1
## 27      8     3
## 28      8     5
## 29      8     7
## 30      8     8
## 31      9     1
## 32      9     2
## 33      9     3
## 34      9     4
## 35      9     5
## 36      9     6
## 37      9     7
## 38      9     8
## 39      9     9
## 40     10     1
## 41     10     2
## 42     10     3
## 43     10     4
## 44     10     5
## 45     10     6
## 46     10     7
## 47     10     8
## 48     10     9
## 49     10    10
## 50     11     1
## 51     11     2
## 52     11     3
## 53     11     4
## 54     11     5
## 55     11     8
## 56     11     9
## 57     11    11
## 58     12     2
## 59     12     3
## 60     12     6
## 61     12     7
## 62     12     8
## 63     12     9
## 64     12    10
## 65     12    11
## 66     12    12
## 67     13     1
## 68     13     2
## 69     13     4
## 70     13     6
## 71     13     8
## 72     13    10
## 73     13    11
## 74     13    12
## 75     13    13
## 76     14     1
## 77     14     2
## 78     14     3
## 79     14     6
## 80     14     7
## 81     14     8
## 82     14    10
## 83     14    11
## 84     14    12
## 85     14    13
## 86     14    14
## 87     15     1
## 88     15     5
## 89     15     6
## 90     15     7
## 91     15     8
## 92     15     9
## 93     15    10
## 94     15    11
## 95     15    12
## 96     15    13
## 97     15    14
## 98     15    15
## 99     16     3
## 100    16     6
## 101    16     7
## 102    16     8
## 103    16    10
## 104    16    11
## 105    16    12
## 106    16    13
## 107    16    14
## 108    16    16
## 109    17     2
## 110    17     4
## 111    17     6
## 112    17     9
## 113    17    11
## 114    17    13
## 115    17    15
## 116    17    17
## 117    18     2
## 118    18     3
## 119    18     5
## 120    18     6
## 121    18     7
## 122    18     8
## 123    18    11
## 124    18    12
## 125    18    13
## 126    18    14
## 127    18    15
## 128    18    16
## 129    18    17
## 130    18    18
## 131    19     1
## 132    19     2
## 133    19     3
## 134    19     4
## 135    19     6
## 136    19     7
## 137    19     8
## 138    19    10
## 139    19    11
## 140    19    12
## 141    19    13
## 142    19    14
## 143    19    15
## 144    19    16
## 145    19    17
## 146    19    18
## 147    19    19
## 148    20     2
## 149    20     3
## 150    20     4
## 151    20     6
## 152    20     7
## 153    20     8
## 154    20     9
## 155    20    10
## 156    20    11
## 157    20    12
## 158    20    13
## 159    20    14
## 160    20    15
## 161    20    16
## 162    20    17
## 163    20    18
## 164    20    20

This results into 164 pairwise connexions (edges). Remove the connexion from one site to itself as it does not represent edges but rather self recruitment.

edges <- filter(edges, SITE1 != SITE2)
nrow(edges)
## [1] 144

Create the binary site-by-edges matrix E. To impose directionality on the diagram and create asymmetric spatial variables, an imaginary site is added upstream of the sampling area (in blue on the graph).

bin.mat <- aem.build.binary(coords=xy,link=edges, plot.connexions = TRUE)

str(bin.mat)
## List of 2
##  $ se.mat: int [1:20, 1:145] 1 1 1 1 1 1 1 1 1 1 ...
##  $ edges : num [1:145, 1:2] 0 1 1 2 1 2 3 1 2 5 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:145] "1" "1" "2" "3" ...
##   .. ..$ : chr [1:2] "from" "to"
bin.mat
## $se.mat
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
##  [1,]    1    0    0    0    0    0    0    0    0     0     0     0     0
##  [2,]    1    1    0    0    0    0    0    0    0     0     0     0     0
##  [3,]    1    1    1    1    0    0    0    1    1     1     0     0     0
##  [4,]    1    1    1    1    1    1    1    1    1     1     1     0     0
##  [5,]    1    1    0    0    0    0    0    1    1     0     0     0     0
##  [6,]    1    1    1    1    1    1    1    1    1     1     1     1     1
##  [7,]    1    1    1    1    1    1    1    1    1     1     1     0     0
##  [8,]    1    1    1    1    1    1    1    1    1     1     1     1     1
##  [9,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [10,]    1    1    1    1    1    1    1    1    1     1     1     0     0
## [11,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [12,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [13,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [14,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [15,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [16,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [17,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [18,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [19,]    1    1    1    1    1    1    1    1    1     1     1     1     1
## [20,]    1    1    1    1    1    1    1    1    1     1     1     1     1
##       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     1     1     1     1     1     1     0     0     0     0     0     0
##  [7,]     0     1     1     1     1     0     0     0     0     0     0     0
##  [8,]     1     1     1     1     1     1     1     1     1     1     1     1
##  [9,]     1     1     1     1     1     1     0     0     0     0     1     1
## [10,]     0     1     1     1     1     0     0     0     0     0     0     0
## [11,]     1     1     1     1     1     1     1     1     1     1     1     1
## [12,]     1     1     1     1     1     1     1     1     1     1     1     1
## [13,]     1     1     1     1     1     1     1     1     1     1     1     1
## [14,]     1     1     1     1     1     1     1     1     1     1     1     1
## [15,]     1     1     1     1     1     1     1     1     1     1     1     1
## [16,]     1     1     1     1     1     1     1     1     1     1     1     1
## [17,]     1     1     1     1     1     1     1     1     1     1     1     1
## [18,]     1     1     1     1     1     1     1     1     1     1     1     1
## [19,]     1     1     1     1     1     1     1     1     1     1     1     1
## [20,]     1     1     1     1     1     1     1     1     1     1     1     1
##       [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     0     0     0     0     0     0     1     1     1     1     1     1
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     1     1     1     1     1     1     1     1     1     1     1     1
##  [9,]     1     1     1     1     1     0     1     1     1     1     1     1
## [10,]     0     0     0     0     0     0     1     1     1     1     1     0
## [11,]     1     1     1     1     1     1     1     1     1     1     1     1
## [12,]     1     1     1     1     1     1     1     1     1     1     1     1
## [13,]     1     1     1     1     1     1     1     1     1     1     1     1
## [14,]     1     1     1     1     1     1     1     1     1     1     1     1
## [15,]     1     1     1     1     1     1     1     1     1     1     1     1
## [16,]     1     1     1     1     1     1     1     1     1     1     1     1
## [17,]     1     1     1     1     1     1     1     1     1     1     1     1
## [18,]     1     1     1     1     1     1     1     1     1     1     1     1
## [19,]     1     1     1     1     1     1     1     1     1     1     1     1
## [20,]     1     1     1     1     1     1     1     1     1     1     1     1
##       [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     1     0     0     0     0     0     0     0     0     0     0     0
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     1     1     1     0     0     0     0     0     0     0     0     0
##  [9,]     1     0     1     0     0     0     0     0     0     0     0     0
## [10,]     1     0     0     0     0     0     0     0     0     0     0     0
## [11,]     1     1     1     1     1     1     1     1     1     1     0     0
## [12,]     1     1     1     1     1     1     1     1     1     1     1     1
## [13,]     1     1     1     1     1     1     1     1     1     1     1     1
## [14,]     1     1     1     1     1     1     1     1     1     1     1     1
## [15,]     1     1     1     1     1     1     1     1     1     1     1     1
## [16,]     1     1     1     1     1     1     1     1     1     1     1     1
## [17,]     1     1     1     1     1     1     1     1     1     1     1     1
## [18,]     1     1     1     1     1     1     1     1     1     1     1     1
## [19,]     1     1     1     1     1     1     1     1     1     1     1     1
## [20,]     1     1     1     1     1     1     1     1     1     1     1     1
##       [,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
## [10,]     0     0     0     0     0     0     0     0     0     0     0     0
## [11,]     0     0     0     0     0     0     0     0     0     0     0     0
## [12,]     1     1     1     1     1     1     0     0     0     0     0     0
## [13,]     1     1     1     1     1     1     1     1     1     1     1     1
## [14,]     1     1     1     1     1     1     1     1     1     1     1     1
## [15,]     1     1     1     1     1     1     1     1     1     1     1     1
## [16,]     1     1     1     1     1     1     1     1     1     1     1     1
## [17,]     1     1     1     1     1     1     1     1     1     1     1     1
## [18,]     1     1     1     1     1     1     1     1     1     1     1     1
## [19,]     1     1     1     1     1     1     1     1     1     1     1     1
## [20,]     1     1     1     1     1     1     1     1     1     1     1     1
##       [,62] [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
## [10,]     0     0     0     0     0     0     0     0     0     0     0     0
## [11,]     0     0     0     0     0     0     0     0     0     0     0     0
## [12,]     0     0     0     0     0     0     0     0     0     0     0     0
## [13,]     1     1     0     0     0     0     0     0     0     0     0     0
## [14,]     1     1     1     1     1     1     1     1     1     1     1     1
## [15,]     1     1     1     1     1     1     1     1     1     1     1     1
## [16,]     1     1     1     1     1     1     1     1     1     1     1     1
## [17,]     1     1     0     0     0     0     0     0     0     0     0     0
## [18,]     1     1     1     1     1     1     1     1     1     1     1     1
## [19,]     1     1     1     1     1     1     1     1     1     1     1     1
## [20,]     1     1     1     1     1     1     1     1     1     1     1     1
##       [,74] [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
## [10,]     0     0     0     0     0     0     0     0     0     0     0     0
## [11,]     0     0     0     0     0     0     0     0     0     0     0     0
## [12,]     0     0     0     0     0     0     0     0     0     0     0     0
## [13,]     0     0     0     0     0     0     0     0     0     0     0     0
## [14,]     0     0     0     0     0     0     0     0     0     0     0     0
## [15,]     1     1     1     1     1     1     1     1     1     1     1     0
## [16,]     0     0     0     0     0     0     0     0     0     0     0     1
## [17,]     0     0     0     0     0     0     0     0     0     0     0     0
## [18,]     0     0     0     0     0     0     0     0     0     0     0     0
## [19,]     0     0     0     0     0     0     0     0     0     0     0     0
## [20,]     0     0     0     0     0     0     0     0     0     0     0     0
##       [,86] [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
## [10,]     0     0     0     0     0     0     0     0     0     0     0     0
## [11,]     0     0     0     0     0     0     0     0     0     0     0     0
## [12,]     0     0     0     0     0     0     0     0     0     0     0     0
## [13,]     0     0     0     0     0     0     0     0     0     0     0     0
## [14,]     0     0     0     0     0     0     0     0     0     0     0     0
## [15,]     0     0     0     0     0     0     0     0     1     1     1     1
## [16,]     1     1     1     1     1     1     1     1     1     1     1     1
## [17,]     0     0     0     0     0     0     0     0     1     1     1     1
## [18,]     0     0     0     0     0     0     0     0     1     1     1     1
## [19,]     0     0     0     0     0     0     0     0     1     1     1     1
## [20,]     0     0     0     0     0     0     0     0     1     1     1     1
##       [,98] [,99] [,100] [,101] [,102] [,103] [,104] [,105] [,106] [,107]
##  [1,]     0     0      0      0      0      0      0      0      0      0
##  [2,]     0     0      0      0      0      0      0      0      0      0
##  [3,]     0     0      0      0      0      0      0      0      0      0
##  [4,]     0     0      0      0      0      0      0      0      0      0
##  [5,]     0     0      0      0      0      0      0      0      0      0
##  [6,]     0     0      0      0      0      0      0      0      0      0
##  [7,]     0     0      0      0      0      0      0      0      0      0
##  [8,]     0     0      0      0      0      0      0      0      0      0
##  [9,]     0     0      0      0      0      0      0      0      0      0
## [10,]     0     0      0      0      0      0      0      0      0      0
## [11,]     0     0      0      0      0      0      0      0      0      0
## [12,]     0     0      0      0      0      0      0      0      0      0
## [13,]     0     0      0      0      0      0      0      0      0      0
## [14,]     0     0      0      0      0      0      0      0      0      0
## [15,]     1     1      1      1      1      1      1      1      1      1
## [16,]     1     1      0      1      1      1      1      1      1      1
## [17,]     1     1      0      0      0      0      0      0      0      0
## [18,]     1     1      0      1      1      1      1      1      1      1
## [19,]     1     1      0      1      1      1      1      1      1      1
## [20,]     1     1      0      1      1      1      1      1      1      1
##       [,108] [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117]
##  [1,]      0      0      0      0      0      0      0      0      0      0
##  [2,]      0      0      0      0      0      0      0      0      0      0
##  [3,]      0      0      0      0      0      0      0      0      0      0
##  [4,]      0      0      0      0      0      0      0      0      0      0
##  [5,]      0      0      0      0      0      0      0      0      0      0
##  [6,]      0      0      0      0      0      0      0      0      0      0
##  [7,]      0      0      0      0      0      0      0      0      0      0
##  [8,]      0      0      0      0      0      0      0      0      0      0
##  [9,]      0      0      0      0      0      0      0      0      0      0
## [10,]      0      0      0      0      0      0      0      0      0      0
## [11,]      0      0      0      0      0      0      0      0      0      0
## [12,]      0      0      0      0      0      0      0      0      0      0
## [13,]      0      0      0      0      0      0      0      0      0      0
## [14,]      0      0      0      0      0      0      0      0      0      0
## [15,]      1      1      1      1      0      1      1      1      1      1
## [16,]      1      1      1      0      1      1      1      1      1      1
## [17,]      0      0      0      0      0      0      0      0      0      0
## [18,]      1      1      1      0      0      1      0      0      0      0
## [19,]      1      1      1      0      0      1      1      1      1      1
## [20,]      1      1      1      0      0      1      0      0      0      0
##       [,118] [,119] [,120] [,121] [,122] [,123] [,124] [,125] [,126] [,127]
##  [1,]      0      0      0      0      0      0      0      0      0      0
##  [2,]      0      0      0      0      0      0      0      0      0      0
##  [3,]      0      0      0      0      0      0      0      0      0      0
##  [4,]      0      0      0      0      0      0      0      0      0      0
##  [5,]      0      0      0      0      0      0      0      0      0      0
##  [6,]      0      0      0      0      0      0      0      0      0      0
##  [7,]      0      0      0      0      0      0      0      0      0      0
##  [8,]      0      0      0      0      0      0      0      0      0      0
##  [9,]      0      0      0      0      0      0      0      0      0      0
## [10,]      0      0      0      0      0      0      0      0      0      0
## [11,]      0      0      0      0      0      0      0      0      0      0
## [12,]      0      0      0      0      0      0      0      0      0      0
## [13,]      0      0      0      0      0      0      0      0      0      0
## [14,]      0      0      0      0      0      0      0      0      0      0
## [15,]      1      1      1      1      1      1      1      1      1      0
## [16,]      1      1      1      1      1      1      1      1      0      1
## [17,]      0      0      0      0      0      0      0      0      0      0
## [18,]      0      0      0      0      0      0      0      0      0      0
## [19,]      1      1      1      1      1      1      1      1      0      0
## [20,]      0      0      0      0      0      0      0      0      0      0
##       [,128] [,129] [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137]
##  [1,]      0      0      0      0      0      0      0      0      0      0
##  [2,]      0      0      0      0      0      0      0      0      0      0
##  [3,]      0      0      0      0      0      0      0      0      0      0
##  [4,]      0      0      0      0      0      0      0      0      0      0
##  [5,]      0      0      0      0      0      0      0      0      0      0
##  [6,]      0      0      0      0      0      0      0      0      0      0
##  [7,]      0      0      0      0      0      0      0      0      0      0
##  [8,]      0      0      0      0      0      0      0      0      0      0
##  [9,]      0      0      0      0      0      0      0      0      0      0
## [10,]      0      0      0      0      0      0      0      0      0      0
## [11,]      0      0      0      0      0      0      0      0      0      0
## [12,]      0      0      0      0      0      0      0      0      0      0
## [13,]      0      0      0      0      0      0      0      0      0      0
## [14,]      0      0      0      0      0      0      0      0      0      0
## [15,]      1      1      1      1      1      1      1      1      1      1
## [16,]      1      1      1      1      1      1      1      1      1      1
## [17,]      0      0      0      0      0      0      0      0      0      0
## [18,]      0      0      0      0      0      0      0      0      0      0
## [19,]      1      1      0      0      0      0      0      0      0      0
## [20,]      0      0      1      1      1      1      1      1      1      1
##       [,138] [,139] [,140] [,141] [,142] [,143] [,144] [,145]
##  [1,]      0      0      0      0      0      0      0      0
##  [2,]      0      0      0      0      0      0      0      0
##  [3,]      0      0      0      0      0      0      0      0
##  [4,]      0      0      0      0      0      0      0      0
##  [5,]      0      0      0      0      0      0      0      0
##  [6,]      0      0      0      0      0      0      0      0
##  [7,]      0      0      0      0      0      0      0      0
##  [8,]      0      0      0      0      0      0      0      0
##  [9,]      0      0      0      0      0      0      0      0
## [10,]      0      0      0      0      0      0      0      0
## [11,]      0      0      0      0      0      0      0      0
## [12,]      0      0      0      0      0      0      0      0
## [13,]      0      0      0      0      0      0      0      0
## [14,]      0      0      0      0      0      0      0      0
## [15,]      1      1      1      1      1      0      1      1
## [16,]      1      1      1      1      0      1      1      1
## [17,]      0      0      0      0      0      0      0      0
## [18,]      0      0      0      0      0      0      0      0
## [19,]      0      0      0      0      0      0      0      0
## [20,]      1      1      1      1      0      0      1      1
## 
## $edges
##     from to
## 1      0  1
## 1      1  2
## 2      1  3
## 3      2  3
## 4      1  4
## 5      2  4
## 6      3  4
## 7      1  5
## 8      2  5
## 9      5  3
## 10     5  4
## 11     1  6
## 12     2  6
## 13     3  6
## 14     1  7
## 15     2  7
## 16     3  7
## 17     4  7
## 18     7  6
## 19     1  8
## 20     3  8
## 21     5  8
## 22     7  8
## 23     1  9
## 24     2  9
## 25     3  9
## 26     4  9
## 27     5  9
## 28     6  9
## 29     7  9
## 30     9  8
## 31     1 10
## 32     2 10
## 33     3 10
## 34     4 10
## 35     5 10
## 36    10  6
## 37     7 10
## 38    10  8
## 39    10  9
## 40     1 11
## 41     2 11
## 42     3 11
## 43     4 11
## 44     5 11
## 45     8 11
## 46     9 11
## 47     2 12
## 48     3 12
## 49     6 12
## 50     7 12
## 51     8 12
## 52     9 12
## 53    10 12
## 54    11 12
## 55     1 13
## 56     2 13
## 57     4 13
## 58     6 13
## 59     8 13
## 60    10 13
## 61    11 13
## 62    12 13
## 63     1 14
## 64     2 14
## 65     3 14
## 66     6 14
## 67     7 14
## 68     8 14
## 69    10 14
## 70    11 14
## 71    12 14
## 72    13 14
## 73     1 15
## 74     5 15
## 75     6 15
## 76     7 15
## 77     8 15
## 78     9 15
## 79    10 15
## 80    11 15
## 81    12 15
## 82    13 15
## 83    14 15
## 84     3 16
## 85     6 16
## 86     7 16
## 87     8 16
## 88    10 16
## 89    11 16
## 90    12 16
## 91    13 16
## 92    14 16
## 93     2 17
## 94     4 17
## 95     6 17
## 96     9 17
## 97    11 17
## 98    13 17
## 99    17 15
## 100    2 18
## 101    3 18
## 102    5 18
## 103    6 18
## 104    7 18
## 105    8 18
## 106   11 18
## 107   12 18
## 108   13 18
## 109   14 18
## 110   18 15
## 111   18 16
## 112   17 18
## 113    1 19
## 114    2 19
## 115    3 19
## 116    4 19
## 117    6 19
## 118    7 19
## 119    8 19
## 120   10 19
## 121   11 19
## 122   12 19
## 123   13 19
## 124   14 19
## 125   19 15
## 126   19 16
## 127   17 19
## 128   18 19
## 129    2 20
## 130    3 20
## 131    4 20
## 132    6 20
## 133    7 20
## 134    8 20
## 135    9 20
## 136   10 20
## 137   11 20
## 138   12 20
## 139   13 20
## 140   14 20
## 141   20 15
## 142   20 16
## 143   17 20
## 144   18 20

For each site, the “ocean current links” will receive the code “1” in a sites-by-edges, all other edges receive the code “0” when creating AEM variables non-weighted (see bin.mat$se.mat).

For the AEM variables weighted, weights can be added to the sites-by-edges matrix by multiplying a the dispersal probabilities from connectivity matrix to the sites-by-edges matrix.

Now, we want to add weights to edges by multiplying these edges by the dispersal probabilities contained in the connectivity matrix. To do so, we remove the self-comparison.

weights <- filter(con.mat.highest.prob.no0, SITE1 != SITE2)
weight.vec <- as.vector(weights[,1])
length(weight.vec)
## [1] 144

Calculate AEM variables ysing the function aem from the package adespatial.This function constructs eigenvectors of a site-by-link matrix. Weights can be applied to the links.

cuke.aem.wt <- adespatial::aem(aem.build.binary = bin.mat, weight = weight.vec, rm.link0 = TRUE) # weight
cuke.aem.nowt <- adespatial::aem(aem.build.binary = bin.mat, rm.link0 = TRUE) # no weight

Generate AEM vectors.

AEM.vectors.wt <- as.data.frame(cuke.aem.wt$vectors)
AEM.vectors.nowt <- as.data.frame(cuke.aem.nowt$vectors)

The eigenfunctions created with this method are orthogonal variables, as is the case for the eigenfunctions created by the PCNM and MEM methods. Save the AEM vectors informations for implementing these values in the RDA framework.

write.table(AEM.vectors.wt, file = "AEM_weight_all_vectors.txt", sep = "\t", quote = F, col.names = T, row.names = F)