Skip to contents

Load long form data

Usage

load_long_form_data(df, warn_uninformative = TRUE)

Arguments

df

data frame with 3 columns: sample_id, locus, allele. Each row is a single observation of an allele at a particular locus for a given sample.

warn_uninformative

boolean whether or not to print message when removing uninformative loci

Value

List structured for run_mcmc() with elements sample_ids, data (list of per-locus lists of binary allele vectors), loci, is_missing (loci by samples logical matrix), and uninformative_loci (loci removed for having a single allele).

Details

Long form data is a data frame with 3 columns: sample_id, locus, allele. Returned data contains vectors sample_ids and loci that are ordered as the results will be ordered from running the MCMC algorithm.

Examples

df <- data.frame(
  sample_id = c("S1", "S1", "S1", "S2", "S2"),
  locus = c("L1", "L1", "L2", "L1", "L2"),
  allele = c("A", "B", "A", "A", "B")
)
dat <- load_long_form_data(df)
dat$loci
#> [1] "L1" "L2"
dat$data[["L1"]]
#> NULL

# A subset of the bundled Namibia data
ids <- unique(namibia_data$sample_id)[1:20]
dat <- load_long_form_data(namibia_data[namibia_data$sample_id %in% ids, ])
str(dat, max.level = 1)
#> List of 5
#>  $ sample_ids        : num [1:20] 531 533 544 548 549 550 554 572 573 577 ...
#>  $ data              :List of 26
#>  $ loci              : chr [1:26] "AS1" "AS11" "AS12" "AS14" ...
#>  $ is_missing        : logi [1:26, 1:20] FALSE FALSE FALSE FALSE FALSE FALSE ...
#>  $ uninformative_loci: chr(0)