Converts a SNPDataLong object to a data.frame, runs PCA, and performs anticlustering on the selected principal components.

runAnticlusteringPCA(object, K = 2, n_pcs = 20, center = TRUE, scale = TRUE)

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 means PCs explaining at least 80% variance).

center

Logical or numeric. Passed to scale via genoToDF. If TRUE, center columns; if numeric, a vector of column means. Default: TRUE.

scale

Logical or numeric. Passed to scale via genoToDF. If TRUE, scale to unit variance; if numeric, a vector of column sds. Default: TRUE.

Value

A list with components:

groups

Integer vector with anticlustering group assignments.

pca

The PCA result object (from stats::prcomp).

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)
}