qpgraph_precompute_f3: Compute f3-statistics from f2-statistics.

qpgraph_precompute_f3R Documentation

Compute f3-statistics from f2-statistics.

Description

Takes a 3d array of f2 block jackknife estimates and computes f3-statistics between the first population p1 and all population pairs i, j: f3(p1; p_i, p_j)

Usage

qpgraph_precompute_f3(
  data,
  pops,
  f3basepop = NULL,
  lambdascale = 1,
  boot = FALSE,
  seed = NULL,
  diag_f3 = 1e-05,
  lsqmode = FALSE
)

Arguments

data

Input data in one of three forms:

  1. A 3d array of blocked f2 statistics, output of f2_from_precomp or extract_f2 (fastest option)

  2. A directory which contains pre-computed f2-statistics

  3. The prefix of genotype files (slowest option)

pops

Populations for which to compute f3-statistics

f3basepop

f3-statistics base population. If NULL (the default), the first population in pops will be used as the basis.

lambdascale

Scales f2-statistics. This has no effect on the fit, but is used in the original qpGraph program to display branch weights on a scale that corresponds to FST distances.

boot

If FALSE (the default), block-jackknife resampling will be used to compute standard errors. Otherwise, block-bootstrap resampling will be used to compute standard errors. If boot is an integer, that number will specify the number of bootstrap resamplings. If boot = TRUE, the number of bootstrap resamplings will be equal to the number of SNP blocks.

seed

Random seed used if boot is TRUE.

diag_f3

Regularization term added to the diagonal elements of the covariance matrix of estimated f3 statistics (after scaling by the matrix trace). In the original qpGraph program, this is fixed at 0.00001.

lsqmode

Least-squares mode. If TRUE, the likelihood score will be computed using a diagonal matrix with 1/(sum(diag(f3_var)) * diag_f3), in place of the inverse f3-statistic covariance matrix. lsqmode = 2 will use the identity matrix instead, which is equivalent to computing the score as the sum of squared residuals (sum((f3_est-f3_fit)^2)). Both of these options do not take the covariance of f3-statistics into account. This can lead to bias, but is more stable in cases where the inverse f3-statistics covariance matrix can not be estimated precisely (for example because the number of populations is large). An alternative to using lsqmode = TRUE which doesn't completely ignore the covariance of f3-statistics is to increase diag_f3.

Value

A list with four items

  1. f3_est a matrix with f3-statistics for all population pairs with the output

  2. ppinv a matrix with the inverse of the f3-statistic covariance matrix

  3. f2out a data frame with f2 estimates

  4. f3out a data frame with f3 estimates

Examples

pops = get_leafnames(example_igraph)
qpgraph_precompute_f3(example_f2_blocks, pops)$f3_est
## Not run: 
qpgraph_precompute_f3(f2_dir, pops)

## End(Not run)

uqrmaie1/admixtools documentation built on Nov. 3, 2024, 12:56 a.m.