8.4 R Exercise Week 5
Task: Assess fine-scale spatial genetic structure in Pulsatilla vulgaris within a single patch, A25: Test for IBD with Mantel rank correlation, and use a Mantel correlogram to assess the range of spatial autocorrelation.
Hints:
Load packages: You may want to load the packages
dplyr
,EcoGenetics
andadegenet
. Alternatively, you can use::
to call functions from packages.Import data, extract adults from A25.
- Use the code below to import the data into gstudio.
- Inspect a few rows of the data.
- Filter the dataset to retain adults (OffID == 0) from site A25 (Population == “A25”).
Pulsatilla.gstudio <- gstudio::read_population(path=system.file("extdata",
"pulsatilla_genotypes.csv",
package = "LandGenCourse"),
type="column", locus.columns=c(6:19),
phased=FALSE, sep=",", header=TRUE)
Plot locations of individuals: use
plot
with the argumentasp = 1
to plot the locations of the sampled individuals from site A25 to scale.Convert to ecogen and genind: use
EcoGenetics::gstudio2ecogen
to convert to anecogen
object. From there, useEcoGenetics::ecogen2genind
to convert to agenind
object.Calculate genetic and Euclidean distance:
- Use
adegenet::propShared
to calculate the proportion of shared alleles at the individual level. (Do not convert to genpop). - Convert to a distance measure by calculating
1 - propShared
. - Check object class. If it is not
dist
, useas.dist
to convert to adist
object. - Use
dist
to calculate Euclidean distance between individuals.
- Use
Mantel test:
- Adapt code from section 4.a to plot pairwise genetic distance against Euclidean distance.
- Do you notice something unusial in the plot? Why are there so few different values of genetic distance?
- Do you think there is spatial autocorrelation? If so, up to what distance?
- Adapt code from section 4.b to test for IBD with a Mantel test, using Spearman rank correlation.
Mantel correlogram: adapt code from section 5.a to create and plot a Mantel correlogram. Interpret the results.
Questions: What is the range of spatial autocorrelation in P. vulgaris in site A25?
- Based on a plot of genetic distance against Euclidean distance?
- Based on where the Mantel correlogram reaches 0?
- Based on statistical significance tests for the Mantel correlogram (with default settings: one-sided alternative “less”, Holm’s adjustment)?