4) Population structure

Population differentiation measures

For these measures, a gtypes object needs to be stratified. For example, we can use the built in example object dloop.g:

dloop.g

<<< dolphin dLoop >>>

Contents: 126 samples, 1 locus, 3 strata
Stratification schemes: broad, fine
Other info: haps.unassigned

Strata summary:
         stratum num.ind num.missing num.haplotypes
1        Coastal      68           0              5
2 Offshore.North      40           0             22
3 Offshore.South      18           0             14

Sequence summary:
  locus num.seqs mean.length mean.num.ns mean.num.indels
1 dLoop       33         402           0             1.8

For sequence data, the degree of nucleotide divergence (pairwise sequence difference) and Nei’s dA can be calculated with nucleotideDivergence():

nucleotideDivergence(dloop.g)
$within
  locus        stratum   mean q.0 q.0.025 q.0.5 q.0.975   q.1
1 dLoop        Coastal 0.0051   0       0 0.005   0.010 0.010
2 dLoop Offshore.North 0.0227   0       0 0.022   0.037 0.050
3 dLoop Offshore.South 0.0187   0       0 0.018   0.038 0.043

$between
  locus       strata.1       strata.2     dA  mean    q.0 q.0.025 q.0.5 q.0.975
1 dLoop        Coastal Offshore.North 0.0061 0.020 0.0000  0.0050 0.020   0.033
2 dLoop        Coastal Offshore.South 0.0062 0.018 0.0075  0.0075 0.018   0.033
3 dLoop Offshore.North Offshore.South 0.0011 0.022 0.0000  0.0000 0.022   0.040
    q.1
1 0.037
2 0.037
3 0.048

This returns a list with a summary of the pairwise distances \(within_ strata and Nei's dA and pairwise distances _\)between strata.

For standard measures of population structure (e.g., Fst, PHIst, Jost’s D, etc.), there are two main functions. The first, overallTest() computes the test statistic and permutation p-value for the global null hypotheses that all individuals have been drawn at random from a single population and stratification was random with respect to individual genotypes. The test will compute all statistics and their respective permutation p-values (if nrep > 0). The statistics computed will be different depending on if the gtypes object provided is haploid or diploid.

Here is an example for haploid sequence data:

ovl <- overallTest(dloop.g)
ovl
$strata.freq

       Coastal Offshore.North Offshore.South 
            68             40             18 

$result
      estimate p.val
CHIsq   189.67 0.001
Fst       0.13 0.001
PHIst     0.29 0.001

The result is a list with the sample size (\(strata.freq_) of each stratum, and a matrix with the values of the test statistic and p-value (_\)result).

For pairwise tests, the pairwiseTest() function is used:

pws <- pairwiseTest(dloop.g)

str(pws)
List of 3
 $ :List of 2
  ..$ strata.freq: 'table' int [1:2(1d)] 68 40
  .. ..- attr(*, "dimnames")=List of 1
  .. .. ..$ : chr [1:2] "Coastal" "Offshore.North"
  ..$ result     : num [1:3, 1:2] 103.871 0.147 0.341 0.001 0.001 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:3] "CHIsq" "Fst" "PHIst"
  .. .. ..$ : chr [1:2] "estimate" "p.val"
 $ :List of 2
  ..$ strata.freq: 'table' int [1:2(1d)] 68 18
  .. ..- attr(*, "dimnames")=List of 1
  .. .. ..$ : chr [1:2] "Coastal" "Offshore.South"
  ..$ result     : num [1:3, 1:2] 86 0.16 0.52 0.001 0.001 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:3] "CHIsq" "Fst" "PHIst"
  .. .. ..$ : chr [1:2] "estimate" "p.val"
 $ :List of 2
  ..$ strata.freq: 'table' int [1:2(1d)] 40 18
  .. ..- attr(*, "dimnames")=List of 1
  .. .. ..$ : chr [1:2] "Offshore.North" "Offshore.South"
  ..$ result     : num [1:3, 1:2] 31.52407 -0.00275 0.05915 0.26 0.558 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:3] "CHIsq" "Fst" "PHIst"
  .. .. ..$ : chr [1:2] "estimate" "p.val"

This produces a list where each element is a unique pair of strata. The results for each pair of strata are formatted the same way as the single result from overallTest().

The pairwise results can be more easily compiled into a single data.frame with pairwiseSummary():

pairwiseSummary(pws)
                                       label       strata.1       strata.2 n.1
1        Coastal (68) v. Offshore.North (40)        Coastal Offshore.North  68
2        Coastal (68) v. Offshore.South (18)        Coastal Offshore.South  68
3 Offshore.North (40) v. Offshore.South (18) Offshore.North Offshore.South  40
  n.2 CHIsq CHIsq_p.val     Fst Fst_p.val PHIst PHIst_p.val
1  40   104       0.001  0.1467     0.001 0.341       0.001
2  18    86       0.001  0.1595     0.001 0.520       0.001
3  18    32       0.260 -0.0027     0.558 0.059       0.060

Here, there is one row for each pairwise test with a formatted label column that provides the strata and sample size and then columns following the individual strata, sample sizes, test statistics, and their p-values.

For a given statistic, one use pairwiseMatrix() to produce a summary matrix that gives the test statistic in the lower left and p-value in the upper right:

pairwiseMatrix(pws, stat = 'Fst')
               Coastal Offshore.North Offshore.South
Coastal             NA         0.0010          0.001
Offshore.North    0.15             NA          0.558
Offshore.South    0.16        -0.0027             NA

The process is exactly the same for diploid data, but other test statistics are computed:

pws.msats <- pairwiseTest(msats.g)
pairwiseSummary(pws.msats)
                                       label       strata.1       strata.2 n.1
1        Coastal (68) v. Offshore.North (40)        Coastal Offshore.North  68
2        Coastal (68) v. Offshore.South (18)        Coastal Offshore.South  68
3 Offshore.North (40) v. Offshore.South (18) Offshore.North Offshore.South  40
  n.2 CHIsq CHIsq_p.val   Ho Ho_p.val   Hs Hs_p.val   Ht Ht_p.val Ht_prime
1  40   477       0.001 0.71    0.002 0.75     1.00 0.81    0.001     0.86
2  18   440       0.001 0.75    0.001 0.76     0.02 0.82    0.001     0.88
3  18    64       0.551 0.83    0.105 0.87     0.19 0.87    0.252     0.87
  Ht_prime_p.val     Dst Dst_p.val Dst_prime Dst_prime_p.val    Fst Fst_p.val
1          0.001  0.0543     0.001    0.1087           0.001  0.067     0.001
2          0.001  0.0588     0.001    0.1177           0.001  0.072     0.001
3          0.401 -0.0017     0.759   -0.0034           0.759 -0.002     0.758
  Fst_prime Fst_prime_p.val   Fis Fis_p.val Gst_prime Gst_prime_p.val
1    0.1260           0.001 0.057      1.00     0.479           0.001
2    0.1342           0.001 0.013      0.99     0.525           0.001
3   -0.0039           0.758 0.049      0.83    -0.028           0.764
  Gst_dbl_prime Gst_dbl_prime_p.val   Dest Dest_p.val Dest_Chao Dest_Chao_p.val
1         0.512               0.001  0.441      0.001    0.4390           0.001
2         0.557               0.001  0.489      0.001    0.4950           0.001
3        -0.031               0.763 -0.026      0.765   -0.0013           0.625
  wcFit wcFit_p.val   wcFst wcFst_p.val wcFis wcFis_p.val
1 0.173       0.001  0.1306       0.001 0.049        1.00
2 0.160       0.001  0.1464       0.001 0.016        1.00
3 0.058       0.771 -0.0042       0.772 0.062        0.23