[R-sig-eco] reorder vegdist objects
Bede-Fazekas Ákos
b|@|ev||@t @end|ng |rom gm@||@com
Mon Jun 3 23:24:45 CEST 2019
Dear Gian,
I'm not a statistician but software developer... hope that other members
of the mailing list are expert of distance matrices and can answer your
question.
Have a nice week,
Ákos
2019.06.03. 17:44 keltezéssel, Gian Maria Niccolò Benucci írta:
> Hi Akos,
>
> Thank you for the code. It worked. I reordered the dist objects as I
> cannot access the dataset of one of the two distance matrix.
>
> > dist_b_reordered <- as.dist(as.matrix(dist_b)[attr(dist_a,
> "Labels"), attr(dist_a, "Labels")])
> > all.equal(dist_a, dist_b_reordered, check.attributes = FALSE)
> [1] "Mean relative difference: 0.8977224"
>
> There is any statistical test that you suggest to compare the two
> distances? I would like to see if the two matrices show a similar
> pattern, e.g. mantel test?
>
> Thanks,
>
> Gian
>
>
>
>
>
>
> On Sat, 1 Jun 2019 at 00:55, Bede-Fazekas Ákos <bfalevlist using gmail.com
> <mailto:bfalevlist using gmail.com>> wrote:
>
> Dear Gian,
> Let's do a small reproducible example:
> library(vegan)
> data(varespec)
> set.seed(12345)
> df_a <- t(varespec)
> df_b <- t(varespec[, sample.int
> <http://sample.int>(ncol(varespec))]) # shuffle the original
> column order
> dist_a <- vegdist(df_a); dist_b <- vegdist(df_b)
> all.equal(dist_a, dist_b, check.attributes = FALSE)
>
> Now, you have two options. If you have access to the original
> data.frame/matrix from which the dist object was created, you can
> reorder the rows of the second dataset to match that of the first
> one.
> Then do the distance matrix calculation again.
> df_b_reordered <- df_b[rownames(df_a), ]
> dist_b_reordered1 <- vegdist(df_b_reordered)
> all.equal(dist_a, dist_b_reordered1, check.attributes = FALSE)
>
> If you have no access to the original dataset and/or can not
> recalculate
> the distance matrix (e.g. due to computer capacity or time), you can
> reorder the distance matrix (both the rows and columns).
> dist_b_reordered2 <- as.dist(as.matrix(dist_b)[attr(dist_a,
> "Labels"),
> attr(dist_a, "Labels")])
> all.equal(dist_a, dist_b_reordered2, check.attributes = FALSE)
>
> HTH,
> Ákos Bede-Fazekas
> Hungarian Academy of Sciences
>
>
> 2019.06.01. 1:53 keltezéssel, Gian Maria Niccolò Benucci írta:
> > Hello,
> >
> > I have two vegan::vegdist objects I want to use into a
> vegan::mantel test.
> > However, rows and columns of the two objects are not in the same
> order. Is
> > there a way to reorder them one another?
> >
> > For example,
> >
> >> dist_a
> > Lycovolu Hupeaust Lycofast Lycodeut
> > Hupeaust 0.9045557
> >
> > Lycofast 0.6835441 0.8569781
> >
> > Lycodeut 0.8036577 0.8294657 0.7958988 ...
> > ...
> >
> >> dist_b
> > Lycodeut Lycofast Lycoscar Lycovolu
> > Lycofast 0.09340659
> >
> > Lycoscar 0.08974359 0.01831502
> >
> > Lycovolu 0.09073476 0.01099655 0.01008080 ...
> > ...
> >
> > Thanks,
> >
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology using r-project.org <mailto:R-sig-ecology using r-project.org>
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecolog
> <https://stat.ethz.ch/mailman/listinfo/r-sig-ecology>y
>
>
>
> /----- Do not print this email unless you really need to. Save paper
> and protect the environment! -----/
[[alternative HTML version deleted]]
More information about the R-sig-ecology
mailing list