r - How to do a Mantel test (in VEGAN package) between geography and genetics WHILE leaving out specific observations? -
i wish carry out mantel test between matrix of geographical distances in kilometers (matrix 1) , corresponding matrix of bray-curtis distances in leave out values 0 geographical distance. (a distance of 0 km represent neighbouring samples not identical , should not pooled, not wholly independent of 1 either). therefore, wish keep them in analysis.
the simple mantel test easy: read in geographical matrix using basic
my_geodist_matrix <-read.table("my_geodist_matrix.txt",header=true,row.names=1)
the matrix looks this:
1top 1bottom 2top 2bottom 3top 3bottom 1top 0 0 20.72 20.72 127.5 127.5 1bottom 0 0 20.72 20.72 127.5 127.5 2top 20.72 20.72 0 0 148.137 148.137 2bottom 20.72 20.72 0 0 148.137 148.137 3top 127.5 127.5 148.137 148.137 0 0 3bottom 127.5 127.5 148.137 148.137 0 0
then, calculate bc distances (using vegan package) thus:
my_otu_table.dist<-vegdist(my_otu_table,method="bray")
(looks this):
1top 1bottom 2top 2bottom 3top 1bottom 0.8341957 2top 0.9948253 0.9908943 2bottom 0.9919492 0.9853757 0.4667466 3top 0.9482715 0.6923454 0.9926684 0.9882600 3bottom 0.9463127 0.6581957 0.9901074 0.9843602 0.1683397
and simple mantel test
mantel(my_geodist_matrix ,my_otu_table.dist)
so far, no trouble @ all. however, when try leave out pairs 0 in geographical matrix , corresponding bray-curtis values, goes wrong.
my_geodist_matrix <- lapply(my_geodist_matrix, function(x){replace(x, x == 0, na)})
and
my_ otu_table.dist[is.na(my_geodist_matrix)] <- na
when mantel test now, r gives following error messages:
error in as.data.frame.default(x[[i]], optional = true) : cannot coerce class ""dist"" data.frame
or
error in cor(as.vector(xdis), ydis, method = method, use = use) : missing observations in cov/cor
how do desired comparison best way (and correctly!)?
Comments
Post a Comment