Standardized population genetic diversity in R

2 min readDec 5, 2019


Genetic diversity estimation per site or group of sites can be biased due to unbalanced sampling designs. There is an expected relationship between the number of sampled individuals in a single population and genetic diversity (e.g., as allelic richness; the total number of alleles).

To overcome the issue, standardized allelic richness and standardized number of private alleles can be determined to the smallest number of individuals within sites or group of sites under multiple randomizations.

The sites or groups of sites with higher standardized genetic diversity than the global mean can be also assessed by testing the proportion of randomizations retrieving higher values than observed.

R code: Standardized population genetic diversity

# Source main functionsource("")# Get example data file at: <- "sampleData.gtx" <- 0
replace <- FALSE
ncode <- 3 <- FALSE
resample.number <- 20
discard.pops <- NULL
number.iteractions <- 999
alfa.test <- 0.05
savefile <- FALSE
save.filename <- "richness"
# Define a vector to cluster populationsclustering.vector <- c(1,1,2,2)
# Run functionRambo(,, ncode, replace,, resample.number, discard.pops, number.iteractions, alfa.test, clustering.vector, savefile, save.filename)

Main citation

Assis, J., Coelho, N. C., Lamy, T., Valero, M., Alberto, F., & Serrão, E. A. (2016). Deep reefs are climatic refugia for genetic diversity of marine forests. Journal of Biogeography, (43), 833–844.




Hi!! I’m Jorge Assis, a Data Scientist, Marine Ecologist, Climate Change Analyst, R and Python Developer based in Portugal []