interlmkdist() (Expand for more details)
The start and end points of the distance measure required need to be defined manually. This is done with a two-column matrix or dataframe with the column names “start” and “end.” For the sake of this example, we are interested in the distances between landmarks 1:2 and 3:4 respectively:
dists <- matrix(c(1,2,3,4),ncol = 2, byrow = T)
colnames(dists) <- c("start", "end")
dists
## start end
## [1,] 1 2
## [2,] 3 4
intlmkdist <- interlmkdist(lmk, dists)
intlmkdist
## [,1] [,2]
## [1,] 1.0732464 3.965878
## [2,] 0.7904719 3.984135
## [3,] 0.8565340 3.705467
## [4,] 1.2985309 4.029318
## [5,] 0.9468429 3.975509
Each column contains one distance measure for each specimen. In this
case, the first column is the distance between landmarks 1 and 2 for
each of the 10 specimens in our dataset.
Calculating interlandmark distances for all possible combinations of landmarks requires a bit more code, but is nonetheless fairly simple:
First, we need to generate a vector of landmark numbers equal to the total number of landmarks in our dataset:
lmkno <- c(1:dim(lmk)[1]) #vector of 1:number of landmarks
lmkno
## [1] 1 2 3 4 5
Next, using the combn function we can generate a matrix
of all possible combinations of those landmarks:
alldist <- matrix(combn(lmkno,2, c),ncol = 2, byrow = T) #returns all pairwise combinations of landmark numbers
colnames(alldist) <- c("start", "end")
alldist
## start end
## [1,] 1 2
## [2,] 1 3
## [3,] 1 4
## [4,] 1 5
## [5,] 2 3
## [6,] 2 4
## [7,] 2 5
## [8,] 3 4
## [9,] 3 5
## [10,] 4 5
intlmkdist <- interlmkdist(lmk, alldist)
intlmkdist
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1.0732464 3.360799 7.094816 7.634875 3.977041 7.395026 7.997329 3.965878 4.400389 0.7336264
## [2,] 0.7904719 3.228808 6.953514 7.331036 3.580447 7.040904 7.463865 3.984135 4.261914 0.5788650
## [3,] 0.8565340 3.175094 6.727441 7.008508 3.519829 6.836761 7.186543 3.705467 3.892784 0.6470026
## [4,] 1.2985309 3.528328 7.312307 7.750283 4.018143 7.359630 7.937849 4.029318 4.302592 0.9678678
## [5,] 0.9468429 2.785570 6.606091 7.110076 3.260097 6.790600 7.382265 3.975509 4.378959 0.8621375