Squared-chord distances between samples: best practice? Paleoecology

Hello,

I'm trying to figure out how to use R to calculate the rate of changes between samples with beetle remains (so I would like the rate of change to be based on squared-chord distances between samples).

Below is a tiny bit of my data, in total it's 19 samples and 283 species, often a species has only one count in one of the 19 samples.

Beetles <- tibble::tribble(
                                ~SpeciesName,  ~S1,  ~S2,  ~S3,  ~S4,  ~S5,  ~S6,
                   "Cychrus caraboides (L.)",    0,    0,    0,    0,    0, 0.01,
              "Leistus terminatus (Hellwig)", 0.01,    0,    0,    0,    0,    0,
                               "Leistus sp.",    0, 0.01,    0,    0,    0,    0,
             "Notiophilus palustris (Duft.)",    0,    0,    0,    0, 0.02,    0,
               "Notiophilus biguttatus (F.)",    0,    0,    0, 0.02,    0,    0,
                  "Loricera pilicornis (F.)",    0,    0,    0,    0,    0, 0.01,
               "Dyschirius globosus (Hbst.)", 0.01,    0,    0,    0,    0,    0,
                "Trechus amplicollis Fairm.",    0, 0.01, 0.05, 0.02,    0,    0
             )
head(Beetles)
#> # A tibble: 6 x 7
#>   SpeciesName                      S1    S2    S3    S4    S5    S6
#>   <chr>                         <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Cychrus caraboides (L.)        0     0        0  0     0     0.01
#> 2 Leistus terminatus (Hellwig)   0.01  0        0  0     0     0   
#> 3 Leistus sp.                    0     0.01     0  0     0     0   
#> 4 Notiophilus palustris (Duft.)  0     0        0  0     0.02  0   
#> 5 Notiophilus biguttatus (F.)    0     0        0  0.02  0     0   
#> 6 Loricera pilicornis (F.)       0     0        0  0     0     0.01

I have read a few techniques, one in the Vegan package and one in another package that I forgot, that show the distances between two different data sets. But I would like to calculate the distances between the columns within one data set (each column is a different sample, S1, S2, S3,..., with a different age) and I couldn't find the solution.

Hi @Schaffie. The distance function for squared chord is in analogue package but cannot be installed. So, if the squared chord equation that you mentioned is the same as the analogue package [https://www.rdocumentation.org/packages/analogue/versions/0.10-0/topics/distance].
The following script can help.

library(tidyverse)

Beetles <- tibble::tribble(
  ~SpeciesName,  ~S1,  ~S2,  ~S3,  ~S4,  ~S5,  ~S6,
  "Cychrus caraboides (L.)",    0,    0,    0,    0,    0, 0.01,
  "Leistus terminatus (Hellwig)", 0.01,    0,    0,    0,    0,    0,
  "Leistus sp.",    0, 0.01,    0,    0,    0,    0,
  "Notiophilus palustris (Duft.)",    0,    0,    0,    0, 0.02,    0,
  "Notiophilus biguttatus (F.)",    0,    0,    0, 0.02,    0,    0,
  "Loricera pilicornis (F.)",    0,    0,    0,    0,    0, 0.01,
  "Dyschirius globosus (Hbst.)", 0.01,    0,    0,    0,    0,    0,
  "Trechus amplicollis Fairm.",    0, 0.01, 0.05, 0.02,    0,    0
)

doubleChord <- function(j, k) {
  res <- 0
  for (i in seq_along(j)) {
    res <- res + (sqrt(j[i]) - sqrt(k[i]))^2
  }
  res
}

Beetles %>%
  as.data.frame() %>%
  column_to_rownames("SpeciesName") %>%
  t() %>%
  usedist::dist_make(doubleChord, "doubleChord")

#           S1         S2         S3         S4         S5
#S2 0.04000000                                            
#S3 0.07000000 0.02527864                                 
#S4 0.06000000 0.03171573 0.02675445                      
#S5 0.04000000 0.04000000 0.07000000 0.06000000           
#S6 0.04000000 0.04000000 0.07000000 0.06000000 0.04000000

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.