DriftTest: Test drift hypothesis

View source: R/DriftTest.R

DriftTestR Documentation

Test drift hypothesis

Description

Given a set of covariance matrices and means for terminals, test the hypothesis that observed divergence is larger/smaller than expected by drift alone using a regression of the between-group variances on the within-group eigenvalues.

Usage

DriftTest(
  means,
  cov.matrix,
  show.plot = TRUE,
  sample.sizes = NULL,
  tol = NULL,
  plot = TRUE
)

Arguments

means

list or array of species means being compared. array must have means in the rows.

cov.matrix

ancestral covariance matrix for all populations

show.plot

Logical. If TRUE, plot of eigenvalues of ancestral matrix by between group variance is showed.

sample.sizes

Optional vector with the number of individuals used to estimate each mean, in the same order as means. If supplied, the expected sampling variance of the means along each eigenvector (eigenvalue times the average of 1/sample.sizes) is subtracted from the between group variances before the regression. See Details.

tol

Optional numeric. If supplied, axes whose ancestral matrix eigenvalue is below tol are dropped from the regression (their log values are set to NA). Eigenvalues close to zero have very large negative logs and become high-leverage points in the regression. Default is NULL, no axes are dropped.

plot

Logical. If FALSE the ggplot is not built and the plot element of the result is NULL, which is much faster (building the plot takes most of the time of the function). Default is TRUE.

Details

Non-positive eigenvalues of cov.matrix (matrices that are not positive definite) have no logarithm; the corresponding axes are excluded from the regression and a warning is issued. Use tol to also exclude near-zero eigenvalues.

Means estimated from samples carry sampling variance proportional to the within-group matrix (W/n), so when divergence among groups is small relative to W/n the between group variances are dominated by sampling error and the slope tends to one regardless of the process that produced the divergence. If sample.sizes is supplied, this expected sampling variance is subtracted. Axes whose corrected variance is not positive (no detectable divergence beyond sampling error) are set to NA, excluded from the regression, and reported with a warning. The corrected slope is a less attenuated estimate of the scaling between divergence and within-group variation, but it is also noisier, so the test based on it is not more powerful than the uncorrected test; it is most useful for estimating the slope and for checking whether divergence along each axis exceeds sampling error. When sample.sizes is NULL (default) the results are identical to previous versions.

Value

list of results containing:

regression: the linear regression between the log of the eigenvalues of the ancestral matrix and the log of the between group variance (projected on the eigenvectors of the ancestral matrix)

coefficient_CI_95: confidence intervals for the regression coefficients

log.between_group_variance: log of the between group variance (projected on the ancestral matrix eigenvectors), corrected for sampling variance if sample.sizes is supplied (NA for axes with non-positive corrected variance)

log.W_eVals: log of the ancestral matrix eigenvalues

plot: plot of the regression using ggplot2

Note

If the regression coefficient is significantly different to one, the null hypothesis of drift is rejected.

Author(s)

Ana Paula Assis, Diogo Melo

References

Marroig, G., and Cheverud, J. M. (2004). Did natural selection or genetic drift produce the cranial diversification of neotropical monkeys? The American Naturalist, 163(3), 417-428. doi:10.1086/381693

Proa, M., O'Higgins, P. and Monteiro, L. R. (2013), Type I error rates for testing genetic drift with phenotypic covariance matrices: A simulation study. Evolution, 67: 185-195. doi: 10.1111/j.1558-5646.2012.01746.x

Examples


#Input can be an array with means in each row or a list of mean vectors
means = array(rnorm(40*10), c(10, 40)) 
cov.matrix = RandomMatrix(40, 1, 1, 10)
DriftTest(means, cov.matrix)

evolqg documentation built on Nov. 29, 2026, 1:08 a.m.

Related to DriftTest in evolqg...