Closed isapetitta closed 3 months ago
The units for euclidean distance are valueless unless you know how they are projected. If they are in degrees (lat/lon), then it might not be possible because you need to account for the curvature of the earth (see https://gis.stackexchange.com/a/380269).
I also notice that there is something that could be improved with the code to get you to a point where you are calculating geographic distance. I've commented below what your code is actually doing:
library(adegenet) # 1. load adegenet
lop <- genind2genpop(lup.genind) # 2. transform lup.genind to a genpop object
lop@other$xy<-lop[,3:4] # 3. subset the genpop object to the
# 3rd and 4th alleles and assign that object
# to the $xy object in the @other slot
lop
Dgen <- dist.genpop(lop,method=1) # 4. calculate Nei's 1972 genetic distance
Dgeo <- dist(lop) # 5. calculate Nei's 1972 genetic distance
library(adegenet)
data(nancycats)
nanpop <- genind2genpop(nancycats)
dim(other(nanpop)$xy)
class(other(nanpop)$xy)
other(nanpop)$xy <- nanpop[,8:9] dim(other(nanpop)$xy)
class(other(nanpop)$xy)
<sup>Created on 2024-04-03 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
The second point: these two calls are exactly the same.
```r
dist.genpop(lop, method = 1)
dist(lop)
If you want to get geographic distance, take a look at section 7 of the basics tutorial.
dist.genpop(lop, method = 1) # genetic distance
dist(other(lop)$xy) # geographic distance
Thank you!!
Hi! I am using the Isolation by Distance function for my data. When I use dist() to calculate geographic distance of my coordinates in the other column of my genepop object, what distance is being calculated and how? What units do I report?
Thanks! My code is below.
library(adegenet) lop <- genind2genpop(lup.genind) lop@other$xy<-lop[,3:4] lop
Dgen <- dist.genpop(lop,method=1) #genetic distance Dgeo <- dist(lop) #geographic distance