Search code examples
rvegan

Can I extract certain dissimilarity values from a bray curtis matrix in R?


I am trying to assess how long a change in stream communities persists following invasive species removals. Community was assessed in a series of streams before and at several time points after the removal. I would like to calculate dissimilarity between the community immediately before and at each time point following removal (i.e. between pre and post 1, pre and post 2, pre and post 3, etc.), then analyze these values across time to determine how long it takes for streams communities to return to pre-removal conditions. Differences in stream parameters are expected to influence the process, so I need to do this by stream. I'm picturing a plot with time on the x axis, dissimilarity on the y axis, and a different function for each stream. Is there a way to pull just these dissimilarity values out of a bray curtis matrix?

This is my first question, I apologize for any missing information or lack of clarity.


Solution

  • If you convert the output from vegdist() to a matrix then you can easily pull out the dissimilarities between pairs of samples, using rownames or indices of the matrix to extract what you want.

    To convert to a matrix use

    distmat <- as.matrix(bc_obj)
    

    where bc_obj is the object returned from vegdist() containing the Bray Curtis distances.