Runs PCA on a SNPDataLong object (via runPCA) and then performs anticlustering on the selected principal components.

runAnticlusteringPCA(
  object,
  K = 2,
  n_pcs = 20,
  center = TRUE,
  scale = TRUE,
  anticlust_method = c("exchange", "fast")
)

Arguments

object

An object of class SNPDataLong.

K

Number of groups for anticlustering, or a vector of group sizes (as in anticlust).

n_pcs

Number of top principal components to use. If < 1, it is interpreted as the proportion of variance to be explained (e.g. 0.8). The fast matrix-free PCA path is used when a fixed number (>= 1) is requested and RSpectra is installed.

center

Logical or numeric, passed to runPCA. Default TRUE.

scale

Logical or numeric, passed to runPCA. Default TRUE.

anticlust_method

Which anticlust optimiser to use. "exchange" (default) calls anticlust::anticlustering; "fast" calls anticlust::fast_anticlustering, which scales to large numbers of individuals and may return different assignments.

Value

A list with components:

groups

Integer vector with anticlustering group assignments.

pca

The PCA result object (a prcomp-like list), as returned by runPCA.

pcs

Numeric matrix of the PCs used for anticlustering.

Examples

if (FALSE) { # requireNamespace("anticlust", quietly = TRUE) && exists("nelore_imputed")
res <- runAnticlusteringPCA(nelore_imputed, K = 2, n_pcs = 0.8)
table(res$groups)
}