tidy.q_matrix: Tidy a Q matrix

View source: R/q_matrix.R

tidy.q_matrixR Documentation

Tidy a Q matrix

Description

Takes a q_matrix object, which is a matrix, and returns a tidied tibble.

Usage

## S3 method for class 'q_matrix'
tidy(x, data, ...)

Arguments

x

A Q matrix object (as returned by q_matrix).

data

An associated tibble (e.g. a gen_tibble), with the individuals in the same order as the data used to generate the Q matrix

...

not currently used

Value

A tidied tibble containing columns:

row

ID of the original observation (i.e. rowname from original data).

Q

Integer indicating a Q component.

value

The proportion for that particular Q value.

Examples

# run the example only if we have the package installed
if (requireNamespace("LEA", quietly = TRUE)) {
  example_gt <- load_example_gt("gen_tbl")

  # Create a gt_admix object
  admix_obj <- example_gt %>% gt_snmf(k = 1:3, project = "force")

  # Extract a Q matrix
  q_mat_k3 <- get_q_matrix(admix_obj, k = 3, run = 1)

  tidy(q_mat_k3, data = example_gt)
}

tidypopgen documentation built on Aug. 28, 2025, 1:08 a.m.