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:

  1. Load packages: You may want to load the packages dplyr, EcoGenetics and adegenet. Alternatively, you can use :: to call functions from packages.

  2. 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)
  1. Plot locations of individuals: use plot with the argument asp = 1 to plot the locations of the sampled individuals from site A25 to scale.

  2. Convert to ecogen and genind: use EcoGenetics::gstudio2ecogen to convert to an ecogen object. From there, use EcoGenetics::ecogen2genind to convert to a genind object.

  3. 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, use as.dist to convert to a dist object.
    • Use dist to calculate Euclidean distance between individuals.
  4. 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.
  5. 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)?