Learn R Programming

bnpsd (version 1.3.13)

admix_prop_indep_subpops: Construct admixture proportion matrix for independent subpopulations

Description

This function constructs an admixture proportion matrix where every individuals is actually unadmixed (draws its full ancestry from a single intermediate subpopulation). The inputs are the vector of subpopulation labels labs for every individual (length n), and the length-k vector of unique subpopulations subpops in the desired order. If subpops is missing, the sorted unique subpopulations observed in labs is used. This function returns the admixture proportion matrix, for each individual 1 for the column corresponding to its subpopulation, 0 otherwise.

Usage

admix_prop_indep_subpops(labs, subpops = sort(unique(labs)))

Arguments

labs

Length-n vector of subpopulation labels

subpops

Optional length-k vector of unique subpopulations in desired order. Stops if subpops does not contain all unique labels in labs (no error if subpops contains additional labels).

Value

The n-by-k admixture proportion matrix. The unique subpopulation labels are given in the column names.

Examples

Run this code
# NOT RUN {
# vector of subpopulation memberships
labs <- c(1, 1, 1, 2, 2, 3, 1)
# admixture matrix with subpopulations (along columns) sorted
admix_proportions <- admix_prop_indep_subpops(labs)

# declare subpopulations in custom order
subpops <- c(3, 1, 2)
# columns will be reordered to match subpops as provided
admix_proportions <- admix_prop_indep_subpops(labs, subpops)

# declare subpopulations with unobserved labels
subpops <- 1:5
# note columns 4 and 5 will be false for all individuals
admix_proportions <- admix_prop_indep_subpops(labs, subpops)

# }

Run the code above in your browser using DataLab